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

   ### Before Creating the Enhancement Request
   
   - [X] I have confirmed that this should be classified as an enhancement 
rather than a bug/feature.
   
   
   ### Summary
   
   
org.apache.rocketmq.broker.transaction.queue.TransactionalMessageServiceImpl#check
   
   <img width="639" alt="e0888c070757a77bc85c73d29aeb5ca" 
src="https://github.com/user-attachments/assets/8d43851a-2fdb-49b1-9c18-9b4e39c628df";
 />
   
   
   ### Motivation
   
   if ((removedOpOffset = removeMap.remove(i)) != null){
                           log.debug("Half offset {} has been committed/rolled 
back", i);
                           opMsgMap.get(removedOpOffset).remove(i);
                           if (opMsgMap.get(removedOpOffset).size() == 0) {
                               opMsgMap.remove(removedOpOffset);
                               doneOpOffset.add(removedOpOffset);
                           }
                       }
   
   ### Describe the Solution You'd Like
   
   if ((removedOpOffset = removeMap.remove(i)) != null){
                           log.debug("Half offset {} has been committed/rolled 
back", i);
                           opMsgMap.get(removedOpOffset).remove(i);
                           if (opMsgMap.get(removedOpOffset).size() == 0) {
                               opMsgMap.remove(removedOpOffset);
                               doneOpOffset.add(removedOpOffset);
                           }
                       }
   
   ### Describe Alternatives You've Considered
   
   事务消息, 回查判断RMQ_SYS_TRANS_HALF_TOPIC消息是否在RMQ_SYS_TRANS_OP_HALF_TOPIC 
中,优化判断方式。之前代码是先判断Map.containsKey,然后进行removeKey,新的方式是直接removeKey != 
null。之前如果Map.containsKey为真,还需要进行额外的一步removeKey操作,新的方式removeKey!= 
null,即判断了Map是否存在key,又移出了对应的key,提升了一点点性能。
   经过多轮测试,在Map.containsKey 
为true为false概率各为50%的情况,第二种方案明显优于第一种方案。而实际生产环境中,事务回查状态为Unknown的场景应该小于50%,在高并发大数据量场景下,个人认为这个小改动对性能还是有一些提升。
   
   Transactional messages: The process involves checking whether messages in 
RMQ_SYS_TRANS_HALF_TOPIC exist in RMQ_SYS_TRANS_OP_HALF_TOPIC, with an 
optimized approach for verification. Previously, the code first used 
Map.containsKey to check existence and then performed removeKey. The new 
approach directly uses removeKey != null.
   
   In the previous method, if Map.containsKey returned true, an additional 
removeKey operation was required. In contrast, the new approach both checks if 
the key exists in the Map and removes the corresponding key in one step, 
offering a slight performance improvement.
   
   After multiple rounds of testing, when the probabilities of Map.containsKey 
being true or false are both 50%, the second approach consistently outperforms 
the first. In actual production environments, the probability of transactional 
checks being in an “Unknown” state should be less than 50%. Therefore, I 
believe this small adjustment provides a minor but meaningful performance 
improvement.
   
   ### Additional Context
   
   _No response_


-- 
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: commits-unsubscr...@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to