Skip to content

[improve][broker] Use array-backed maps for Key Shared dispatch - #292

Open
lhotari wants to merge 1 commit into
lh-improve-send-release-listfrom
lh-improve-key-shared-maps
Open

lhotari wants to merge 1 commit into
lh-improve-send-release-listfrom
lh-improve-key-shared-maps

Conversation

@lhotari

@lhotari lhotari commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Motivation

Each Key_Shared dispatch batch creates two consumer-keyed maps: one groups entries selected for each consumer and the other tracks the consumer's remaining permits. These short-lived HashMaps allocate a node for every participating consumer and spend measurable CPU in HashMap.putVal while the dispatcher monitor is held.

Modifications

Use FastUtil Object2ObjectOpenHashMap for the two batch-local maps and size them from the connected consumer count. The maps keep the same Consumer.equals and hashCode semantics, values, and lifetime. Routing, permit accounting, ordering, and monitor scope are unchanged.

Add a focused JMH benchmark that constructs both maps and groups 1,000 entries across ten consumers.

Verifying this change

The focused benchmark measured:

Implementation Time Allocation
JDK HashMap 20.768 us/op 15,056.1 B/op
FastUtil open hash map 10.416 us/op 14,640.1 B/op
Change 49.9% faster 416.0 B/op less

A fanout screen used 500 producer connections, one topic, twenty Key_Shared subscriptions, and ten consumers per subscription. Two changed runs and three unchanged runs delivered every one of the expected twenty million fanout copies with zero duplicate, out-of-order, or invalid messages. Mean producer rates were 32,101 and 31,980 msg/s respectively, a flat 0.38% difference within run variation. The end-to-end runs are correctness and material-regression evidence; no whole-workload throughput gain is claimed.

Validation:

  • PersistentStickyKeyDispatcherMultipleConsumersTest
  • two-fork JMH run with GC allocation profiler
  • ./gradlew quickCheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant