xiaobing395845388 commented on a change in pull request #1267: 采用java8 
hashmap的散列算法  hashcode右移16位后与hashcode异或 散列效果更好
URL: https://github.com/apache/rocketmq/pull/1267#discussion_r294225314
 
 

 ##########
 File path: 
client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByHash.java
 ##########
 @@ -25,12 +26,12 @@
 
     @Override
     public MessageQueue select(List<MessageQueue> mqs, Message msg, Object 
arg) {
-        int value = arg.hashCode();
-        if (value < 0) {
-            value = Math.abs(value);
-        }
+        return mqs.get(indexForQueue(mqs.size(), arg));
+    }
 
-        value = value % mqs.size();
-        return mqs.get(value);
+    private int indexForQueue(int length, Object key) {
+        int h = (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
+        return h & (length - 1);
 
 Review comment:
   default of queue nums is 4 ,we recommend it power of 2 , donnot we? we can 
sign if you want your bussiness message ordered by using 
'SelectMessageQueueByHash' , you can config your  queue nums   power of 2 for 
good performance, like hashmap,if you sign the constructor of hashmap 
'HashMap(int initialCapacity) ',  initialCapacity if not be power of 2 ,maybe 
bug  also ,moreever  ,the code before really perform not balance

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to