biheto opened a new issue, #11620:
URL: https://github.com/apache/rocketmq/issues/11620

   ### Before Creating the Enhancement Request
   
   - [x] This improves existing behavior without adding a feature or changing 
routing semantics.
   
   ### Summary
   
   Avoid redundant ordered-map lookups and temporary tail-map views in 
`ConsistentHashRouter.routeNode`.
   
   ### Motivation
   
   `AllocateMessageQueueConsistentHash.allocate` calls `routeNode` for each 
message queue. The current implementation constructs `ring.tailMap(hashVal)`, 
checks whether that view is empty, finds its first key (or the ring's first 
key), then calls `ring.get` to retrieve the node. These operations repeat tree 
traversal for the same result and create a temporary view.
   
   A local JMH comparison of the actual public method, including the default 
MD5 hashing work, measured 128 physical nodes / 10 virtual nodes each at 
479.735 +/- 53.218 ns/op and 216.039 B/op before, versus 365.068 +/- 34.362 
ns/op and 136.026 B/op after. The error is JMH's 99.9% confidence error. With 8 
physical nodes, timing intervals overlap, although allocation also falls. This 
is a routing-method microbenchmark; it excludes ring construction and does not 
establish an end-to-end rebalance improvement.
   
   ### Describe the Solution You Would Like
   
   Use the existing TreeMap through `NavigableMap.ceilingEntry(hashVal)`, 
falling back to `firstEntry()` at the end of the ring. Return the physical node 
from that entry directly. Keep empty-ring handling, hashing, collision 
handling, virtual-node placement and membership updates unchanged. No public 
API, configuration, dependency or retained cache is needed.
   
   A local implementation and boundary tests are ready for a linked PR. The 
tests cover exact matches, successor selection, wrap-around, empty rings, 
signed hash extremes and collisions after node removal.
   
   ### Describe Alternatives You Have Considered
   
   Using `ceilingKey` followed by `get` removes the tail-map view but still 
searches the tree again. A cached result or a replacement ring data structure 
would add invalidation or mutation complexity that is unnecessary here.
   
   ### Additional Context
   
   Inspected `develop` at `e114b542620c4169d016f25b63c2c377b2e279a7`. The 
existing MD5 concurrency report #11264 is a separate issue; this optimization 
does not change thread-safety guarantees.
   
   Windows / Oracle JDK 17.0.4.1 / Intel i5-12500H / JMH 1.37. Both benchmark 
runs used the same logical processor, two forks, five one-second warmups, ten 
one-second measurements and `-Xms256m -Xmx256m`, with the GC profiler. OpenAI 
Codex assisted with investigation, implementation and validation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to