Repository navigation
[improve][broker] Skip the size cap estimate when there are no messages to replay - #26954
Merged
lhotari merged 2 commits intoOct 17, 2026
Merged
Conversation
…es to replay PersistentDispatcherMultipleConsumers.readMoreEntries asks getMessagesToReplayNow for the messages to replay before each normal read. getMessagesToReplayNow first estimated the number of entries that fit the read's byte budget (ManagedCursor.applyMaxSizeCap, which walks the ledgers' metadata from the read position), and then found that there was nothing to replay, the common case; the normal read then estimates it again. In a profile of 2,000 Key_Shared consumers on 3,000 topics, the estimate was 1.25 % of the broker's CPU samples, half of it in getMessagesToReplayNow. getMessagesToReplayNow returns an empty set before the estimate when the delayed delivery tracker has no messages available and the redelivery set is empty. hasMessageAvailable is called once, as before, so it still updates the tracker's timer. Assisted-by: Claude Code (claude-opus-5-5)
lhotari
requested review from
Technoboy-,
codelipenghui,
dao-jun,
david-streamlio,
merlimat and
nodece
October 16, 2026 20:59
codelipenghui
approved these changes
Oct 16, 2026
codelipenghui
left a comment
Contributor
There was a problem hiding this comment.
Reviewed ba4e4ac. No actionable findings identified within the reviewed scope. The new regression test and existing Shared/Key_Shared delayed-delivery tests passed. One optional, non-blocking test-coverage suggestion inline.
…playNow's skip Assisted-by: Claude Code (claude-opus-5-5)
merlimat
added a commit
to void-ptr974/pulsar
that referenced
this pull request
Oct 18, 2026
…ated inline A factory that completes newTrackerAsync() inline, such as the in-memory one, never paused the dispatch: the read that found the delayed message is still in progress. Only resume the dispatch with readMoreEntriesAsync() when the creation completed later, or on a retry. testGetMessagesToReplayNowChecksDelayedTrackerOnce (added by apache#26954) stubbed only newTracker(), so its factory mock returned no tracker from newTrackerAsync(). It now stubs newTrackerAsync().
This file contains hidden or 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
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.
Motivation
PersistentDispatcherMultipleConsumers.readMoreEntriesasksgetMessagesToReplayNowfor the messages to replay before each normal read.getMessagesToReplayNowfirst estimated how many entries fit the read's byte budget (ManagedCursor.applyMaxSizeCap, which walks the ledgers' metadata from the read position), and only then found that there was nothing to replay, which is the common case. The normal read then estimates it again. In a broker profile of an IoT telemetry scenario (2,000 Key_Shared consumers on 3,000 topics), the estimate was 1.25 % of the broker's CPU samples, half of them ingetMessagesToReplayNow.Modifications
getMessagesToReplayNowreturns an empty set before the estimate when the delayed delivery tracker has no messages available and the redelivery set is empty.hasMessageAvailableis still called once, so it still updates the delayed delivery tracker's timer.Verifying this change
This change added tests and can be verified as follows:
PersistentStickyKeyDispatcherMultipleConsumersTestthat checks the size cap isn't estimated when there's nothing to replay, and is estimated when there's a message to replay.In the broker profile with this change,
getMessagesToReplayNowis 0.05 % of the samples.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes