jpisaac commented on code in PR #2169: URL: https://github.com/apache/phoenix/pull/2169#discussion_r2124960833
########## 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: nit: Is the histogram key different than threadpool name? ########## phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/HTableThreadPoolHistograms.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * Creates a collection of histograms for capturing multiple stats related to HTable thread pool + * utilization and contention. + * <br/><br/> + * Supports capturing additional metadata about the stats in the form of key/value pairs a.k.a. tags + * . By default supports two tags i.e. servers and connectionProfile. "servers" tag specified + * the quorum string used in URL for establishing Phoenix connection. This can ZK quorum, + * master quorum, etc., based on the HBase connection registry. "connectionProfile" identifies + * the principal used in URL to create separate CQSI instances for different principals. + * <br/> + * Custom tags can also be specified as String key/value pairs using + * {@link #addTag(String, String)}. + * <br/><br/> + * Internally this class uses {@link org.HdrHistogram.Histogram}. At the time of instantiation of + * an instance of this class HdrHistograms get initialized for each of the stats being collected. + * <br/><br/> + * To view list of the stats being collected please refer {@link HistogramName}. + */ +public class HTableThreadPoolHistograms { + public enum Tag { + servers, + connectionProfile, Review Comment: nit: maybe use cqsiName instead of connectionProfile? In OSS principal => CQSI Name. ########## 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); + Review Comment: nit: good to add comments on what should be the key? ########## phoenix-core-client/src/main/java/org/apache/phoenix/job/HTableThreadPoolWithUtilizationStats.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.job; + +import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; +import org.apache.phoenix.monitoring.HTableThreadPoolHistograms; +import org.apache.phoenix.monitoring.HTableThreadPoolMetricsManager; +import org.apache.phoenix.util.PhoenixRuntime; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; + +public class HTableThreadPoolWithUtilizationStats extends ThreadPoolExecutor { + + private final String htableThreadPoolHistogramsName; + private final Supplier<HTableThreadPoolHistograms> hTableThreadPoolHistogramsSupplier; + + /** + * A wrapper over traditional ThreadPoolExecutor with instrumentation for capturing utilization Review Comment: nit: good to add some comments on how all the newly added classes interact ########## phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/HTableThreadPoolHistograms.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; + +import java.util.List; + +/** Review Comment: nit: good to add a comment that this holds per CQSI histograms ########## phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/HTableThreadPoolHistograms.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.apache.hbase.thirdparty.com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * Creates a collection of histograms for capturing multiple stats related to HTable thread pool + * utilization and contention. + * <br/><br/> + * Supports capturing additional metadata about the stats in the form of key/value pairs a.k.a. tags + * . By default supports two tags i.e. servers and connectionProfile. "servers" tag specified + * the quorum string used in URL for establishing Phoenix connection. This can ZK quorum, + * master quorum, etc., based on the HBase connection registry. "connectionProfile" identifies + * the principal used in URL to create separate CQSI instances for different principals. + * <br/> + * Custom tags can also be specified as String key/value pairs using + * {@link #addTag(String, String)}. + * <br/><br/> + * Internally this class uses {@link org.HdrHistogram.Histogram}. At the time of instantiation of + * an instance of this class HdrHistograms get initialized for each of the stats being collected. + * <br/><br/> + * To view list of the stats being collected please refer {@link HistogramName}. + */ +public class HTableThreadPoolHistograms { + public enum Tag { + servers, + connectionProfile, + } + + public enum HistogramName { + ActiveThreadsCount, + QueueSize, + } + + final private UtilizationHistogram activeThreadsHisto; + final private UtilizationHistogram queuedSizeHisto; + + public HTableThreadPoolHistograms(long maxThreadPoolSize, long maxQueueSize) { + activeThreadsHisto = new UtilizationHistogram(maxThreadPoolSize, + HistogramName.ActiveThreadsCount.name()); + queuedSizeHisto = new UtilizationHistogram(maxQueueSize, HistogramName.QueueSize.name()); + } + + public void updateActiveThreads(long activeThreads) { Review Comment: nit: Add comments - what these updates mean and also for other setters in this class -- 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