Conversation
Assisted-by: Codex
lhotari
force-pushed
the
lh-perfopt-dedup-producer-state
branch
from
September 19, 2026 16:34
4328dda to
23d4917
Compare
lhotari
changed the base branch from
lh-perfopt-dedup-producer-state-base
to
lh-perfopt-repl-snapshot-timestamp
September 19, 2026 16:34
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
Broker-side duplicate admission currently synchronizes on one map for the entire topic. Messages from different producers therefore contend on the same monitor before their managed-ledger adds are submitted. This becomes expensive when many producer connections publish to one topic even though sequence ordering only needs coordination between calls using the same producer name.
Modifications
Use the existing
ConcurrentMapoperations to update the highest pushed sequence ID with aputIfAbsent/conditionalreplaceloop. Updates for one producer remain linearizable, including the brief overlap possible during a reconnect, while unrelated producers no longer serialize on a topic-wide monitor.The replication-v2 path retains its existing synchronization because its ledger-ID and entry-ID values must be checked and updated as one pair. Snapshot, recovery, persistence, and inactive-producer cleanup retain the existing map representation and behavior.
Verifying this change
A focused JMH benchmark measured:
The shared-producer case models an exceptional reconnect overlap. Normal operation has one active connection for a producer name, while distinct producer names are the case this change improves. Accepted updates allocate 24 bytes in both implementations; retries in the deliberately contended same-producer case raised the candidate to about 31 bytes/op.
A broker lock profile with 500 stable producers, one topic, and twenty Key_Shared subscriptions with ten consumers each attributed 22.46% of sampled lock-wait weight to the normal-producer deduplication monitor. The changed implementation had no samples on that monitor.
An unprofiled candidate was bracketed by runs of the unchanged implementation:
The candidate was 5.3% above the arithmetic mean of the two surrounding runs. The exact percentage is host-specific; the stronger evidence is the removal of a topic-wide monitor shared by unrelated producer names. Every run reported zero duplicate, out-of-order, or invalid messages.
Validation:
./gradlew quickCheck./gradlew spotlessCheck checkstyleMain checkstyleTest