-
Notifications
You must be signed in to change notification settings - Fork 343
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
[feat]: Support auto scaled consumer receiver queue #976
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shibd
reviewed
Mar 5, 2023
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.
Great! After a preliminary look, I left some comments.
I see that the unit tests are commented on, and you can finish them up. Can you do a benchmark? Just like this one: apache/pulsar#14494 (comment)
Gleiphir2769
changed the title
[feat]: Support auto scaled consumer receiver queue
[feat]: Draft: Support auto scaled consumer receiver queue
Mar 7, 2023
Gleiphir2769
changed the title
[feat]: Draft: Support auto scaled consumer receiver queue
Draft: [feat]: Support auto scaled consumer receiver queue
Mar 7, 2023
Gleiphir2769
changed the title
Draft: [feat]: Support auto scaled consumer receiver queue
[feat]: Support auto scaled consumer receiver queue
Mar 10, 2023
Gleiphir2769
force-pushed
the
auto_scaled_consumer
branch
from
March 14, 2023 01:30
4a2ebb0
to
57a1340
Compare
shibd
reviewed
Mar 14, 2023
shibd
reviewed
Mar 14, 2023
shibd
approved these changes
Mar 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Master Issue: #927
Motivation
Note: This is part of the work for PIP 74 in go client.
The memory limit in consumer side relys on flow control. So we need to firstly support auto scaled consumer receiver queue before we implement the consumer side memory limitation.
Why should we support auto scaled consumer first before supporting consumer client memory limit?
The main memory consumption on the consumer side comes from the messages that the consumer prefetches from the broker. Currently, the number of prefetched messages depends on the "current available permits" which represents the messages that have been delivered to the user. When the
availablePermits
reach a certain threshold, the client will send aFlow
request to the broker to prefetch messages. The current threshold is half of the "receiverQueueSize" (default 1000).pulsar-client-go/pulsar/consumer_partition.go
Lines 194 to 207 in 352c463
If we do not support auto scaled consumer receiver queue, the
Flow
threshold will be fixed. We cannot dynamically adjust the number of prefetched messages, resulting in the inability to control consumer memory. So auto scaled consumer receiver queue needs to be supported first.How does "auto scaled consumer receiver queue" work?
In consumer side, all controls related to message pulling are actually controlling the
Flow
. For example,receiverQueueSize
controls theFlow
by controlling the size of the receiver queue. ReceiverQueuequeueCh
can receive more messages thanreceiverQueueSize
because queueCh is achan []*message
.pulsar-client-go/pulsar/consumer_partition.go
Line 296 in 352c463
If we want to control the
Flow
threshold, we should make thequeueSize
can be auto scaled. There are mainly two problems to be solved.When the consumption rate required by the user is greater than the configured rate, we increase the configured rate. This condition can be expressed as, before triggering a new Flow to obtain new messages, the number of messages that the current consumer has received (i.e., current available permits + current messages in
queueCh
) is greater than the current queue size.In the Java client,
expectMoreIncomingMessages
is triggered by "empty reveive".https://github.com/apache/pulsar/blob/da30b2e211d0a097abfa8d0392f1fd4b13a46328/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L478-L482
In the Go Client, we can not get the "empty reveive" because the
messageCh
is exposed to user to async consume. So weexpectMoreIncomingMessages
whenmessageCh
is not full.pulsar-client-go/pulsar/consumer_partition.go
Lines 1278 to 1283 in 352c463
More details in #927 .
Modifications
currentQueueSize
andscaleReceiverQueueHint
to controlFlow
rate.AutoScaledReceiverQueueSize
option forConsumer
Verifying this change
Here is a test with pulsar-perf on local standalone server to confirm the effect of this PR.
Non-partitioned topic consumer
3-partitioned topic consumer