szetszwo commented on code in PR #5420:
URL: https://github.com/apache/ozone/pull/5420#discussion_r1355728528


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneProtocolMessageDispatcher.java:
##########
@@ -83,11 +83,15 @@ public RESPONSE processRequest(
       }
 
       long startTime = System.currentTimeMillis();
-
-      RESPONSE response = methodCall.apply(request);
-
-      protocolMessageMetrics.increment(type,
-          System.currentTimeMillis() - startTime);
+      protocolMessageMetrics.increaseConcurrency();
+      RESPONSE response;
+      try {
+        response = methodCall.apply(request);
+      } finally {
+        protocolMessageMetrics.increment(type,
+            System.currentTimeMillis() - startTime);
+        protocolMessageMetrics.decreaseConcurrency();
+      }

Review Comment:
   Let's use a `org.apache.ratis.util.UncheckedAutoCloseable`, i.e.
   ```java
   //processRequest
         final RESPONSE response;
         try (UncheckedAutoCloseable ignored = 
protocolMessageMetrics.measure(type)) {
           response = methodCall.apply(request);
         }
   ```
   ```java
   //ProtocolMessageMetrics
     public UncheckedAutoCloseable measure(KEY key) {
       final long startTime = System.currentTimeMillis();
       concurrency.incrementAndGet();
   
       return () -> {
         concurrency.decrementAndGet();
         counters.get(key).incrementAndGet();
         elapsedTimes.get(key).addAndGet(System.currentTimeMillis() - 
startTime);
       };
     }
   ```



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/ProtocolMessageMetrics.java:
##########
@@ -44,6 +45,8 @@ public class ProtocolMessageMetrics<KEY> implements 
MetricsSource {
   private Map<KEY, AtomicLong> elapsedTimes =
       new ConcurrentHashMap<>();
 
+  private AtomicInteger concurrency = new AtomicInteger(0);

Review Comment:
   Let's make it `final`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to