-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce precise topic publish rate limiting #7078
Conversation
183766a
to
e124a91
Compare
/pulsarbot run-failure-checks |
@aloyszhang Could you please add some tests for the changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. overall lgtm. @aloyszhang thanks for the help. It would be better to have a unit test to protect this part of code.
I'll add some test. |
what if we reduce |
@rdhabalia Agree with you that |
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PublishRateLimiter.java
Show resolved
Hide resolved
/pulsarbot run-failure-checks |
1 similar comment
/pulsarbot run-failure-checks |
@codelipenghui I have add tests for preciseTopicPublishRateLimite, and all check passed. PTAL |
@aloyszhang nice contribution! |
Fixes apache#6975 ### Motivation For now, pulsar limits publish rate of topic by a period task runs every `topicPublisherThrottlingTickTimeMillis`. That means in the time `topicPublisherThrottlingTickTimeMillis`, the limit can't take effect. This PR enable precise topic publish rate limit on broker.
Fixes apache#6975 ### Motivation For now, pulsar limits publish rate of topic by a period task runs every `topicPublisherThrottlingTickTimeMillis`. That means in the time `topicPublisherThrottlingTickTimeMillis`, the limit can't take effect. This PR enable precise topic publish rate limit on broker.
…pache#7239) # Motivation The [PR](apache#7078) introduce precise topic publish rate limiting on broker. But the doc is not updated accordingly. ### Modifications Update the Pulsar doc: Reference > Pulsar configuration > broker
…erEnable=true (#10384) ### Motivation When using `preciseTopicPublishRateLimiterEnable=true` (introduced by #7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance ### Modifications - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) ### Open issue The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.)
…erEnable=true (apache#10384) ### Motivation When using `preciseTopicPublishRateLimiterEnable=true` (introduced by apache#7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance ### Modifications - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) ### Open issue The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.)
…erEnable=true (#10384) ### Motivation When using `preciseTopicPublishRateLimiterEnable=true` (introduced by #7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance ### Modifications - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) ### Open issue The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.) (cherry picked from commit ded806f)
…erEnable=true (#10384) When using `preciseTopicPublishRateLimiterEnable=true` (introduced by #7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.) (cherry picked from commit ded806f)
…erEnable=true (apache#10384) When using `preciseTopicPublishRateLimiterEnable=true` (introduced by apache#7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.) (cherry picked from commit ded806f) (cherry picked from commit 41ad624)
…erEnable=true (apache#10384) ### Motivation When using `preciseTopicPublishRateLimiterEnable=true` (introduced by apache#7078) setting for rate limiting, there are various issues: - updating the limits doesn't set either boundary when changing the limits from a bounded limit to unbounded. - each topic will create a scheduler thread for each limiter instance - each topic will never release the scheduler thread when the topic gets unloaded / closed - updating the limits didn't close the scheduler thread related to the replaced limiter instance ### Modifications - Fix updating of the limits by cleaning up the previous limiter instances before creating new limiter instances - Use `brokerService.pulsar().getExecutor()` as the scheduler for the rate limiter instances - Add resource cleanup hooks for topic closing (unload) ### Open issue The existing code has a difference in passing the `rateLimitFunction`: https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PrecisPublishLimiter.java#L80-L86 It's passed to the `topicPublishRateLimiterOnMessage`, but not to `topicPublishRateLimiterOnByte` . It is unclear whether this is intentional. The `rateLimitFunction` is `() -> this.enableCnxAutoRead()` https://github.com/apache/pulsar/blob/69a173a82c89893f54dbe5b6f422249f66ea5418/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java#L913 (This also raises a question whether rate limiting works consistently when multiple topics share the same connection.)
Fixes #6975
Motivation
For now, pulsar limits publish rate of topic by a period task runs every
topicPublisherThrottlingTickTimeMillis
. That means in the timetopicPublisherThrottlingTickTimeMillis
, the limit can't take effect.This PR enable precise topic publish rate limit on broker.