wang-jiahua commented on code in PR #10517:
URL: https://github.com/apache/rocketmq/pull/10517#discussion_r3417590031
##########
broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java:
##########
@@ -58,11 +60,26 @@ public void suspendPullRequest(final String topic, final
int queueId, final Pull
}
private String buildKey(final String topic, final int queueId) {
- StringBuilder sb = new StringBuilder(topic.length() + 5);
- sb.append(topic);
- sb.append(TOPIC_QUEUEID_SEPARATOR);
- sb.append(queueId);
- return sb.toString();
+ String[] keys = buildKeyCache.get(topic);
+ if (keys != null && queueId >= 0 && queueId < keys.length) {
+ String cached = keys[queueId];
+ if (cached != null) {
+ return cached;
+ }
+ }
+ String key = topic + TOPIC_QUEUEID_SEPARATOR + queueId;
+ if (topic != null && queueId >= 0) {
+ int len = Math.max(queueId + 1, 16);
+ keys = buildKeyCache.computeIfAbsent(topic, t -> new String[len]);
+ if (queueId >= keys.length) {
+ String[] grown = new String[queueId + 16];
+ System.arraycopy(keys, 0, grown, 0, keys.length);
+ buildKeyCache.put(topic, grown);
+ keys = grown;
+ }
+ keys[queueId] = key;
Review Comment:
This file has been removed from the PR per reviewer feedback.
##########
broker/src/main/java/org/apache/rocketmq/broker/transaction/TransactionMetricsFlushService.java:
##########
@@ -41,10 +41,15 @@ public void run() {
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) {
Review Comment:
Good point. Changed `>` to `>=` to avoid skipping persist when elapsed time
equals the interval exactly.
--
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]