codelipenghui commented on code in PR #19502:
URL: https://github.com/apache/pulsar/pull/19502#discussion_r1105181994


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherSingleActiveConsumer.java:
##########
@@ -136,6 +139,24 @@ protected boolean pickAndScheduleActiveConsumer() {
         }
     }
 
+    private int peekConsumerIndexFromHashRing(NavigableMap<Integer, Integer> 
hashRing) {
+        int hash = Murmur3Hash32.getInstance().makeHash(topicName);
+        Map.Entry<Integer, Integer> ceilingEntry = hashRing.ceilingEntry(hash);
+        return ceilingEntry != null ? ceilingEntry.getValue() : 
hashRing.firstEntry().getValue();
+    }
+
+    private NavigableMap<Integer, Integer> makeHashRing(int consumerSize) {
+        NavigableMap<Integer, Integer> hashRing = new TreeMap<>();
+        for (int i = 0; i < consumerSize; i++) {
+            for (int j = 0; j < CONSUMER_CONSISTENT_HASH_REPLICAS; j++) {
+                String key = consumers.get(i).consumerName() + j;

Review Comment:
   I understand your point. I'm also thinking about it to avoid building the 
hash ring for each consumer adding/removing. But the issue is a higher priority 
consumer might be added. Add maintaining a hash ring is also memory resource 
consumption.
   
   I will do a test later. In most cases, consumers should be under hundreds.



-- 
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