This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 8ae35c08fa4 MINOR: add DCL on get or create meter for performance
improvement (#22084)
8ae35c08fa4 is described below
commit 8ae35c08fa46aa4b61b37c56e70b59f70a5bb83e
Author: Bolin Lin <[email protected]>
AuthorDate: Sat Apr 18 14:10:31 2026 -0400
MINOR: add DCL on get or create meter for performance improvement (#22084)
We have synchronized on method `getOrCreateMeter()`. It will cause the
process lock here every time, it would be better to lock when we
actually need to create the meter, otherwise we can just return the
existed value.
Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai
<[email protected]>
---
.../java/org/apache/kafka/network/metrics/RequestMetrics.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git
a/server/src/main/java/org/apache/kafka/network/metrics/RequestMetrics.java
b/server/src/main/java/org/apache/kafka/network/metrics/RequestMetrics.java
index 2960e9000b7..9220cc4edfc 100644
--- a/server/src/main/java/org/apache/kafka/network/metrics/RequestMetrics.java
+++ b/server/src/main/java/org/apache/kafka/network/metrics/RequestMetrics.java
@@ -192,9 +192,13 @@ public class RequestMetrics {
tags.put("error", error.name());
}
- private synchronized Meter getOrCreateMeter() {
+ private Meter getOrCreateMeter() {
if (meter == null) {
- meter = metricsGroup.newMeter(ERRORS_PER_SEC, "requests",
TimeUnit.SECONDS, tags);
+ synchronized (this) {
+ if (meter == null) {
+ meter = metricsGroup.newMeter(ERRORS_PER_SEC,
"requests", TimeUnit.SECONDS, tags);
+ }
+ }
}
return meter;
}