Skip to content

[ISSUE #10490] Eliminate per-RPC allocation from Logback status, TopicMessageType toLowerCase, and RemotingHelper eager evaluation#10491

Open
wang-jiahua wants to merge 2 commits into
apache:developfrom
wang-jiahua:misc/metrics-per-rpc-microfixes
Open

[ISSUE #10490] Eliminate per-RPC allocation from Logback status, TopicMessageType toLowerCase, and RemotingHelper eager evaluation#10491
wang-jiahua wants to merge 2 commits into
apache:developfrom
wang-jiahua:misc/metrics-per-rpc-microfixes

Conversation

@wang-jiahua

Copy link
Copy Markdown
Contributor

Summary

Three independent per-RPC micro-allocations eliminated:

1. Logback NopStatusListener

Add <statusListener class="ch.qos.logback.core.status.NopStatusListener"/> to rmq.broker.logback.xml to suppress Logback internal status event callbacks.

2. TopicMessageType.metricsValue cache

getMetricsValue() was calling value.toLowerCase() per invocation. Now caches metricsValue as a final field with Locale.ROOT.

3. RemotingHelper eager evaluation fix

Map.getOrDefault(code, String.valueOf(code)) eagerly evaluates String.valueOf(code) even on cache hit. Changed to get() + null check.

Dependency

Stacked on PR #10443. Currently includes #10443 changes in the diff; will rebase on develop after #10443 merges to show only the 3 files above.

Files (delta on top of #10443)

File Change
broker/src/main/resources/rmq.broker.logback.xml +2: NopStatusListener
common/.../attribute/TopicMessageType.java +3/-1: metricsValue cached field with Locale.ROOT
remoting/.../common/RemotingHelper.java +4/-2: getOrDefaultget + null check

wangjiahua.wjh added 2 commits June 12, 2026 16:42
…, TopicMessageType toLowerCase, and RemotingHelper eager evaluation
Copilot AI review requested due to automatic review settings June 12, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR reduces per-call allocations in hot paths by introducing reusable OpenTelemetry AttributeKey singletons for metrics labels and by avoiding eager default-string creation in request/response code formatting.

Changes:

  • Add typed AttributeKey label constants for broker/remoting metrics and migrate selected call sites to use them.
  • Optimize request/response code description helpers to avoid unnecessary String.valueOf(...) allocations when a mapping exists.
  • Precompute/canonicalize metric label values and adjust logging configuration behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
remoting/src/main/java/org/apache/rocketmq/remoting/metrics/RemotingMetricsManager.java Switches attribute building to use typed AttributeKey constant for protocol type.
remoting/src/main/java/org/apache/rocketmq/remoting/metrics/RemotingMetricsConstant.java Introduces reusable typed AttributeKey singletons for remoting metric labels.
remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java Avoids eager default-string construction in code-to-description helpers.
common/src/main/java/org/apache/rocketmq/common/attribute/TopicMessageType.java Caches lowercase metrics label value to avoid repeated toLowerCase() and enforce Locale.ROOT.
broker/src/main/resources/rmq.broker.logback.xml Adds a NopStatusListener, changing visibility of Logback status output.
broker/src/main/java/org/apache/rocketmq/broker/metrics/PopMetricsManager.java Migrates selected label puts to typed AttributeKey constants.
broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java Migrates multiple metrics label puts to typed AttributeKey constants.
broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsConstant.java Introduces reusable typed AttributeKey singletons for broker metric labels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


<configuration scan="true" scanPeriod="30 seconds">

<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
Comment on lines +29 to +30
// Pre-built typed AttributeKey singletons. Use these in AttributesBuilder.put()
// on hot paths to avoid allocating a fresh InternalAttributeKeyImpl per call.
Comment on lines +70 to +71
// Pre-built typed AttributeKey singletons. Use these in AttributesBuilder.put()
// on hot paths to avoid allocating a fresh InternalAttributeKeyImpl per call.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.57895% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.03%. Comparing base (82a6a78) to head (077be95).
⚠️ Report is 19 commits behind head on develop.

Files with missing lines Patch % Lines
.../rocketmq/broker/metrics/BrokerMetricsManager.java 0.00% 25 Missing ⚠️
...etmq/remoting/metrics/RemotingMetricsConstant.java 0.00% 5 Missing ⚠️
...che/rocketmq/broker/metrics/PopMetricsManager.java 33.33% 4 Missing ⚠️
...pache/rocketmq/remoting/common/RemotingHelper.java 0.00% 4 Missing ⚠️
...ketmq/remoting/metrics/RemotingMetricsManager.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10491      +/-   ##
=============================================
- Coverage      48.06%   48.03%   -0.04%     
- Complexity     13313    13322       +9     
=============================================
  Files           1377     1377              
  Lines         100632   100729      +97     
  Branches       12995    13012      +17     
=============================================
+ Hits           48369    48384      +15     
- Misses         46344    46393      +49     
- Partials        5919     5952      +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by github-manager-bot

Summary

This PR eliminates three per-RPC micro-allocations on the hot path: Logback status listener overhead, TopicMessageType.metricsValue repeated toLowerCase(), and RemotingHelper eager String.valueOf() evaluation. Additionally, it pre-builds OTel AttributeKey singletons to avoid per-call InternalAttributeKeyImpl allocation.

Findings

  • [Info] TopicMessageType.java — Caching metricsValue with Locale.ROOT is correct and avoids per-call allocation. Good use of Locale.ROOT for deterministic casing.

  • [Info] RemotingHelper.java — The get() + null check pattern replacing getOrDefault(code, String.valueOf(code)) is a valid optimization to avoid eager evaluation. Consider adding a brief inline comment explaining why the null-check pattern is used instead of getOrDefault, since the intent is not immediately obvious to readers.

  • [Info] BrokerMetricsConstant.java / RemotingMetricsConstant.java — Pre-building AttributeKey singletons is a sound optimization for OTel hot paths. The alignment style (extra spaces for =) is consistent within the block but may trigger checkstyle rules if the project enforces no-multi-spaces. Worth verifying CI passes.

  • [Warning] The PR description mentions this is stacked on PR #10443. The diff currently includes 8 files (5 extra from #10443). Reviewers should focus on the 3 core delta files. Please rebase onto develop after #10443 merges to keep the diff clean.

Suggestions

  • Consider adding a microbenchmark (JMH) to quantify the per-RPC allocation reduction, especially for the AttributeKey singleton optimization. This would help justify the change and prevent regression.
  • The NopStatusListener addition is fine, but consider documenting in a comment why it was added (suppress Logback internal status events to avoid per-RPC allocation).

Verdict

Clean performance optimization with no correctness concerns. The changes are well-targeted and low-risk.


Automated review by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants