Repository navigation
[improve][broker] Avoid read locks in Key_Shared consumer selection - #26591
Merged
merlimat merged 1 commit intoSep 15, 2026
Merged
Conversation
Assisted-by: Codex
merlimat
approved these changes
Sep 15, 2026
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
ConsistentHashingStickyKeyConsumerSelector.selectacquires a shared read lock and searches a tree for every selection. Consumer membership changes much less frequently than messages are dispatched, so the lookup can use a precomputed representation that avoids the read lock.Modifications
The snapshot retains an additional array representation of the ring and moves copying work to membership updates. This favors stable membership over frequent consumer churn.
Verifying this change
Passed locally:
spotlessCheck checkstyleMain checkstyleTest,quickCheck, benchmark packaging, and 20 scoped test invocations with no failures or retries:ConsistentHashingStickyKeyConsumerSelectorTest(14 cases).KeySharedSubscriptionTest.testOrderingWhenAddingConsumers,testRemoveFirstConsumerandtestCheckConsumersWithSameName(six invocations).KeySelectorLookupBenchmarkuses the actual selector with 100 hash points per consumer and impact reporting enabled. Two forks, three warmup/five measurement iterations of one second, one thread, 512 MiB G1 and the GC profiler:At 50 consumers, an add/remove pair allocates about 78 KB more. Both runs reached 100°C with thermal throttling, so these component timings do not establish a portable speedup or broker throughput gain. Local concurrency tests supplement the immutable-snapshot publication argument; they cannot prove every possible interleaving.
Does this pull request potentially affect one of the following parts:
Selection uses volatile snapshot publication instead of the membership read lock. Membership mutation remains serialized; public APIs and dispatch ordering contracts are unchanged.