[do not merge] [improve] [broker] Make the dispatch rate limit more precise when subscription is created #18581
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.
This PR should merge after #18553.
Motivation
The Dispatch rate limiter serves two purposes:
But the current design has the following problems:
available permits
indicates how many messages the client needs, and then uses the rate limiter to determine how many entries to read. If batch production is not enabled, it is working. When batch production is enabled, the rate limiter counts the number of entries as the number of messages, resulting in excessive entries to be read.In PR #6719,
preciseDispatcherFlowControl
was added to optimize the above problem: If enabledpreciseDispatcherFlowControl
, we callavailablePermits / avgMessagesPerEntry
to calculate how many entries to read.After PR #18553, there are still such scenarios: failing to get
avgMessagesPerEntry
resulting in reading excessive messages:avgMessagesPerEntry
.Modifications
avgMessagesPerEntry
on the topic, used ifavgMessagesPerEntry
could not be found in subscriptions.avgMessagesPerEntry
is not initialized (it could also be called the first reading), at most one message can be read. Just like the original design: only one message is read whenledger.getStats().getEntrySizeAverage()
is not initialized.ledger.getStats().getEntrySizeAverage()
instead of creating another attributetopic.avgMessagesPerEntry
? Because ledger stat is not set immediately after produce messages, need to wait for the scheduled task(default interval 60 seconds) inManagedLedgerFactoryImpl
.pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Lines 3391 to 3400 in a165bda
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: