This is an automated email from the ASF dual-hosted git repository.

RongtongJin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 971d568433 [ISSUE #10515] Fix TransactionMetricsFlushService busy spin 
bug (#10517)
971d568433 is described below

commit 971d568433804ebb586e6c6bdd9342dff9471384
Author: Jiahua Wang <[email protected]>
AuthorDate: Wed Jun 17 15:01:48 2026 +0800

    [ISSUE #10515] Fix TransactionMetricsFlushService busy spin bug (#10517)
    
    Co-authored-by: wangjiahua.wjh <[email protected]>
---
 .../broker/transaction/TransactionMetricsFlushService.java       | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionMetricsFlushService.java
 
b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionMetricsFlushService.java
index 948f9fbc8e..0f3f24f2c8 100644
--- 
a/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionMetricsFlushService.java
+++ 
b/broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionMetricsFlushService.java
@@ -41,10 +41,15 @@ public class TransactionMetricsFlushService extends 
ServiceThread {
         long start = System.currentTimeMillis();
         while (!this.isStopped()) {
             try {
-                if (System.currentTimeMillis() - start > 
brokerController.getBrokerConfig().getTransactionMetricFlushInterval()) {
+                // Bug fix: original code only called waitForRunning inside 
the if-branch,
+                // so on every iteration where the interval hadn't elapsed yet 
the loop
+                // spun without yielding (~170 CPU samples in JFR on idle 
broker).
+                // Now we always wait, then check whether enough time has 
passed to persist.
+                long interval = 
brokerController.getBrokerConfig().getTransactionMetricFlushInterval();
+                this.waitForRunning(interval);
+                if (System.currentTimeMillis() - start >= interval) {
                     start = System.currentTimeMillis();
                     
brokerController.getTransactionalMessageService().getTransactionMetrics().persist();
-                    
waitForRunning(brokerController.getBrokerConfig().getTransactionMetricFlushInterval());
                 }
             } catch (Throwable e) {
                 log.error("Error occurred in " + getServiceName(), e);

Reply via email to