wang-jiahua opened a new issue, #10441:
URL: https://github.com/apache/rocketmq/issues/10441

   ### Before Creating the Enhancement Request
   
   - [x] I have confirmed that this should be classified as an enhancement 
rather than a bug/feature.
   
   
   ### Summary
   
   Cache `OpenTelemetry AttributeKey` instances as static finals instead of 
creating new instances per RPC call. Also cache 
`RemotingCodeDistributionHandler` counters with volatile inline cache, use 
`TopicMessageType.of()` direct lookup instead of `values()` iteration, and add 
Logback `NopStatusListener` to suppress startup log noise.
   
   **Scope**: 9 files in `broker/metrics`, `remoting/metrics`, 
`remoting/netty`, `common/attribute`
   
   ### Motivation
   
   JFR heap dump analysis shows **38,182 `InternalAttributeKeyImpl` instances** 
alive during a sampling window, but only **6 distinct key names** 
(`request_code`, `response_code`, `is_long_polling`, `is_system`, 
`message_type`, `topic`). The root cause is `AttributesBuilder.put(String, 
...)` calling `AttributeKey.stringKey(name)` on every invocation, which `new`s 
a key object without caching.
   
   At ~45k TPS, this creates 135k–180k throwaway `AttributeKey` objects per 
second, contributing to GC pressure.
   
   ### Describe the Solution You'd Like
   
   1. **`BrokerMetricsConstant` / `RemotingMetricsConstant`**: Change `LABEL_*` 
from `String` to `AttributeKey<String>` / `AttributeKey<Boolean>` static 
finals. Keep `String` aliases via `.getKey()` for view/name references.
   2. **`BrokerMetricsManager` / `RemotingMetricsManager` / 
`PopMetricsManager`**: Replace `put(String, value)` calls with 
`put(AttributeKey, value)` overloads.
   3. **`RemotingCodeDistributionHandler`**: Add volatile inline cache for 
`countInbound` / `countOutbound` methods to avoid repeated 
`AttributeKey.stringKey()` calls per request code.
   4. **`TopicMessageType`**: Replace `values()` loop with direct `if-else` 
lookup in `of()` method.
   5. **`rmq.broker.logback.xml`**: Add `<statusListener 
class="ch.qos.logback.core.status.NopStatusListener"/>`.
   
   ### Describe Alternatives You've Considered
   
   - **`String.intern()` at call sites**: Would reduce String duplication but 
not the `AttributeKey` allocation itself.
   - **OpenTelemetry `AttributeKey` internal cache**: The default 
`InternalAttributeKeyImpl` does not cache by name; relying on upstream to add 
caching is uncertain and out of our control.
   
   ### Additional Context
   
   - Verified on 4×ECS (8c/30G) with 128 producer threads, 1KB body, Temurin 
JDK 21.
   - This PR has zero functional impact — only changes metric label 
construction paths. All existing metrics continue to report identically.


-- 
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]

Reply via email to