sanjeet006py commented on code in PR #2169:
URL: https://github.com/apache/phoenix/pull/2169#discussion_r2128104431


##########
phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/HTableThreadPoolMetricsManager.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.monitoring;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+/**
+ * Central place where we keep track of all the HTable thread pool utilization 
and contention
+ * level metrics for all the HTable thread pools.
+ */
+public class HTableThreadPoolMetricsManager {
+
+    private static final Logger LOGGER =
+            LoggerFactory.getLogger(HTableThreadPoolMetricsManager.class);
+
+    private static final ConcurrentHashMap<String, HTableThreadPoolHistograms>
+            threadPoolHistogramsMap = new ConcurrentHashMap<>();
+
+   public static Map<String, List<HistogramDistribution>> 
getHistogramsForAllThreadPools() {
+        Map<String, List<HistogramDistribution>> map = new HashMap<>();
+        for (Map.Entry<String, HTableThreadPoolHistograms> entry :
+                threadPoolHistogramsMap.entrySet()) {
+            HTableThreadPoolHistograms hTableThreadPoolHistograms = 
entry.getValue();
+            map.put(entry.getKey(),
+                    
hTableThreadPoolHistograms.getThreadPoolHistogramsDistribution());
+        }
+        return map;
+   }
+
+   private static HTableThreadPoolHistograms getThreadPoolHistograms(
+           String histogramKey, Supplier<HTableThreadPoolHistograms> supplier) 
{
+        HTableThreadPoolHistograms hTableThreadPoolHistograms =
+                threadPoolHistogramsMap.get(histogramKey);
+        if (hTableThreadPoolHistograms == null) {
+            synchronized (HTableThreadPoolMetricsManager.class) {
+                hTableThreadPoolHistograms = 
threadPoolHistogramsMap.get(histogramKey);
+                if (hTableThreadPoolHistograms == null) {
+                    hTableThreadPoolHistograms = supplier.get();
+                    if (hTableThreadPoolHistograms != null) {
+                        threadPoolHistogramsMap.put(histogramKey, 
hTableThreadPoolHistograms);
+                    }
+                }
+            }
+        }
+        return hTableThreadPoolHistograms;
+   }
+
+   public static void updateActiveThreads(String histogramKey, int 
activeThreads,

Review Comment:
   Yes, `histogramKey` is different from thread pool name. I have added details 
on how to pick a histogramKey name and how keeping it different from thread 
pool name can be helpful as we do it for CQSI level thread pool.



-- 
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: issues-unsubscr...@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to