xiaobing395845388 opened a new issue #2148: URL: https://github.com/apache/rocketmq/issues/2148
The issue tracker is **ONLY** used for bug report(feature request need to follow [RIP process](https://github.com/apache/rocketmq/wiki/RocketMQ-Improvement-Proposal)). Keep in mind, please check whether there is an existing same report before your raise a new one. Alternately (especially if your communication is not a bug report), you can send mail to our [mailing lists](http://rocketmq.apache.org/about/contact/). We welcome any friendly suggestions, bug fixes, collaboration and other improvements. Please ensure that your bug report is clear and that it is complete. Otherwise, we may be unable to understand it or to reproduce it, either of which would prevent us from fixing the bug. We strongly recommend the report(bug report or feature request) could include some hints as the following: **BUG REPORT** 1. Please describe the issue you observed: - What did you do (The steps to reproduce)? - What did you expect to see? - What did you see instead? 2. Please tell us about your environment: 3. Other information (e.g. detailed explanation, logs, related issues, suggestions how to fix, etc): **FEATURE REQUEST** 1. Please describe the feature you are requesting. 在顺序消费的业务场景下,使用SelectMessageQueueByHash 作为生产消息时候的队列选择器,目前client中的hash分配实现方法如下: ``` public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) { int value = arg.hashCode(); if (value < 0) { value = Math.abs(value); } value = value % mqs.size(); return mqs.get(value); } ``` 使用Math.abs(hashcode)的情况可能导致broker中的队列出现分配不均的情况,需要优化此hash算法 fork源码后优化方法如下: public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) { return mqs.get(indexForQueue(mqs.size(), arg)); } public int indexForQueue(int length, Object key) { int h = key.hashCode(); if ((length & (length - 1)) == 0) { return (h ^ (h >>> 16)) & (length - 1); } return Math.abs(h % length); } 建议TOPIC的queueNum配置为2的N次方,这时使用hashmap的hash算法,这样队列选择的会均衡,同时也兼容原来的算法 2. Provide any additional detail on your proposed use case for this feature. 3. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have). Are you currently using any workarounds to address this issue? 4. If there are some sub-tasks using -[] for each subtask and create a corresponding issue to map to the sub task: - [sub-task1-issue-number](example_sub_issue1_link_here): sub-task1 description here, - [sub-task2-issue-number](example_sub_issue2_link_here): sub-task2 description here, - ... ---------------------------------------------------------------- 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]
