Skip to content
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

[Issue 8599] Fix DispatchRateLimiter does not take effect #8611

Merged

Conversation

wangjialing218
Copy link
Contributor

@wangjialing218 wangjialing218 commented Nov 18, 2020

Fixes #8599
Fixes #4777

Motivation

Pulsar current support topic level and subscription level dispatch rate limiter by using DispatchRateLimiter. When consumers connected to broker and start reading entry, broker judge whether rate limit is exceeded before reading, and increasing the permits after reading finished by call tryAcquire(). When there are multi consumers using one DispatchRateLimiter, these consumers could start reading together and may increasing the acquiredPermits far more than permits after reading finished. As acquiredPermits will reset to 0 every second, all consumers could start reading in the next second and dispatch rate limiter will take no effect in such case.

Modifications

This PR change the behaviour of DispatchRateLimiter, minus permits every second instead of reset acquiredPermits to 0, and the reading will stop for a while until acquiredPermits return to a value less than permits .

Verifying this change

RateLimiterTest.testDispatchRate()

@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch 2 times, most recently from 0326f81 to 917d29e Compare November 19, 2020 02:43
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch from 917d29e to 2b74b82 Compare November 19, 2020 08:48
@315157973
Copy link
Contributor

If the rate limit is 100 msg/s, and I request 10000 msg concurrently at the same time, 10000 messages will still be read, but in the next 100 seconds, none of the messages will be read. This kind of scenario is very easy to simulate, just set the ReceiveQueueSize of MultiConsumer to be larger. Is this side effect too big?

@wangjialing218
Copy link
Contributor Author

If the rate limit is 100 msg/s, and I request 10000 msg concurrently at the same time, 10000 messages will still be read, but in the next 100 seconds, none of the messages will be read. This kind of scenario is very easy to simulate, just set the ReceiveQueueSize of MultiConsumer to be larger. Is this side effect too big?

Yes,if we start concurrently read at same time, all conumser could start there first reading and make dispatch rate far over the limiter, this could be another issue and this PR does not aim to solve this.
This PR make none messages read in the next 100 seconds to let the average dispatch rate return to 100 msg/s at last. In some case it is useful. Consider a topic we don't need to dispatch in real time, we could set a low dispatch rate and just keep the data in bookkeeper, left the network resource to other topics.

@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch from 2b74b82 to 21193ad Compare November 24, 2020 10:49
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@jiazhai
Copy link
Member

jiazhai commented Nov 25, 2020

/pulsarbot run-failure-checks

@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie added this to the 2.8.0 milestone Nov 30, 2020
@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch from 332ce71 to 1c6a1ef Compare February 23, 2021 01:30
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@zymap
Copy link
Member

zymap commented Feb 23, 2021

/pulsarbot run-failure-checks

@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch from 1c6a1ef to a1e564a Compare February 24, 2021 01:28
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@zymap
Copy link
Member

zymap commented Feb 24, 2021

@sijie @codelipenghui @rdhabalia @merlimat Please take a review at this PR. Thanks

@zymap
Copy link
Member

zymap commented Feb 25, 2021

push this to the next release.

@wangjialing218 wangjialing218 force-pushed the branch-refine-dispatch-rate-limiter branch from a1e564a to 2af9a90 Compare March 3, 2021 02:43
@wangjialing218
Copy link
Contributor Author

/pulsarbot run-failure-checks

@eolivelli
Copy link
Contributor

@lhotari FYI

@codelipenghui codelipenghui force-pushed the branch-refine-dispatch-rate-limiter branch from 2af9a90 to d10c45b Compare May 21, 2021 08:37
@lhotari
Copy link
Member

lhotari commented May 21, 2021

It seems that with the changes in this PR, the RateLimiter class now has multiple algorithms that is activated with the isDispatchRateLimiter flag. Wouldn't it be better to split 2 separate RateLimiter implementations that implement different algorithms?

In text books, there are algorithms such as leaky bucket and token bucket . Both algorithms have several variations and in some ways they are very similar algorithms but looking from the different point of view. It would possibly be easier to conceptualize and understand a rate limiting algorithm if common algorithm names and implementation choices mentioned in text books would be referenced in the implementation. This is more like an idea if the rate limiter classes get refactored and split as part of some other PRs.

Another problem with the rate limiting are the 2 separate limits: number of messages and number of bytes. The rate limiting seems to behave in the incorrect way if those limits are both hit in some connection that is being rate limited. This is an issue in the "precise topic rate limiting" implementation. There are some comments about the challenge: #10384 (comment) .
Is it also an issue in dispatch rate limiter?

@codelipenghui
Copy link
Contributor

codelipenghui commented May 21, 2021

@lhotari Good point, Could you please open a new issue for your last comment? This PR fixes the bug of the current implementation, It's better to use a separate issue to track the new implementation of the RateLimiter.

@codelipenghui codelipenghui merged commit 02fc06e into apache:master May 23, 2021
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
Fixes apache#8599
Fixes apache#4777

### Motivation

Pulsar current support topic level and subscription level dispatch rate limiter by using `DispatchRateLimiter`.  When consumers connected to broker and start reading entry, broker judge whether rate limit is exceeded before reading, and increasing the permits after reading finished by call tryAcquire().  When there are multi consumers using one `DispatchRateLimiter`, these consumers could start reading together and may increasing the `acquiredPermits` far more than `permits` after reading finished. As `acquiredPermits` will reset to 0 every second, all consumers could start reading in the next second and dispatch rate limiter will take no effect in such case.

### Modifications

This PR change the behaviour of `DispatchRateLimiter`, minus `permits` every second instead of reset `acquiredPermits` to 0, and the reading will stop for a while until `acquiredPermits` return to a value less than  `permits` .

### Verifying this change
RateLimiterTest.testDispatchRate()
michaeljmarshall pushed a commit that referenced this pull request Dec 10, 2021
Fixes #8599
Fixes #4777

Pulsar current support topic level and subscription level dispatch rate limiter by using `DispatchRateLimiter`.  When consumers connected to broker and start reading entry, broker judge whether rate limit is exceeded before reading, and increasing the permits after reading finished by call tryAcquire().  When there are multi consumers using one `DispatchRateLimiter`, these consumers could start reading together and may increasing the `acquiredPermits` far more than `permits` after reading finished. As `acquiredPermits` will reset to 0 every second, all consumers could start reading in the next second and dispatch rate limiter will take no effect in such case.

This PR change the behaviour of `DispatchRateLimiter`, minus `permits` every second instead of reset `acquiredPermits` to 0, and the reading will stop for a while until `acquiredPermits` return to a value less than  `permits` .

RateLimiterTest.testDispatchRate()

(cherry picked from commit 02fc06e)
@michaeljmarshall michaeljmarshall added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Dec 10, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Fixes apache#8599
Fixes apache#4777

### Motivation

Pulsar current support topic level and subscription level dispatch rate limiter by using `DispatchRateLimiter`.  When consumers connected to broker and start reading entry, broker judge whether rate limit is exceeded before reading, and increasing the permits after reading finished by call tryAcquire().  When there are multi consumers using one `DispatchRateLimiter`, these consumers could start reading together and may increasing the `acquiredPermits` far more than `permits` after reading finished. As `acquiredPermits` will reset to 0 every second, all consumers could start reading in the next second and dispatch rate limiter will take no effect in such case.

### Modifications

This PR change the behaviour of `DispatchRateLimiter`, minus `permits` every second instead of reset `acquiredPermits` to 0, and the reading will stop for a while until `acquiredPermits` return to a value less than  `permits` .

### Verifying this change
RateLimiterTest.testDispatchRate()
RobertIndie pushed a commit that referenced this pull request Apr 11, 2023
### Motivation
After PR #8611, the acquiring permits can be larger than configured msg-rate if used by subscribing. But doc was not updated in time.

### Modifications

fix the outdated doc
Demogorgon314 pushed a commit to Demogorgon314/pulsar that referenced this pull request Apr 11, 2023
### Motivation
After PR apache#8611, the acquiring permits can be larger than configured msg-rate if used by subscribing. But doc was not updated in time.

### Modifications

fix the outdated doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants