This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 9c644f1809 🐛 fix thread pool metrics be gc recycle problem (#11793)
9c644f1809 is described below
commit 9c644f180988016ec30db74ed3f869f221f46689
Author: songxiaosheng <[email protected]>
AuthorDate: Mon Mar 13 17:04:39 2023 +0800
🐛 fix thread pool metrics be gc recycle problem (#11793)
* :bug: fix push metadata code location
* :bug: fix thread pool metrics be gc recycle problem
---
.../collector/sample/ThreadPoolMetricsSampler.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadPoolMetricsSampler.java
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadPoolMetricsSampler.java
index 87e3c7d4d2..adc4118d4f 100644
---
a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadPoolMetricsSampler.java
+++
b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadPoolMetricsSampler.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.store.DataStore;
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
+import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
import org.apache.dubbo.metrics.model.MetricsKey;
import org.apache.dubbo.metrics.model.ThreadPoolMetric;
@@ -53,7 +54,7 @@ public class ThreadPoolMetricsSampler implements
MetricsSampler {
private FrameworkExecutorRepository frameworkExecutorRepository;
private DataStore dataStore;
private final Map<String, ThreadPoolExecutor> sampleThreadPoolExecutor =
new ConcurrentHashMap<>();
-
+ private final ConcurrentHashMap<String, ThreadPoolMetric>
threadPoolMetricMap = new ConcurrentHashMap<>();
public ThreadPoolMetricsSampler(DefaultMetricsCollector collector) {
this.collector = collector;
}
@@ -77,14 +78,14 @@ public class ThreadPoolMetricsSampler implements
MetricsSampler {
private List<MetricSample> createMetricsSample(String name,
ThreadPoolExecutor executor) {
List<MetricSample> list = new ArrayList<>();
- ThreadPoolMetric poolMetrics = new
ThreadPoolMetric(collector.getApplicationName(), name, executor);
-
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_CORE_SIZE,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getCorePoolSize));
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_LARGEST_SIZE,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getLargestPoolSize));
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_MAX_SIZE,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getMaximumPoolSize));
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_ACTIVE_SIZE,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getActiveCount));
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_THREAD_COUNT,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getPoolSize));
- list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_QUEUE_SIZE,
poolMetrics.getTags(), THREAD_POOL, poolMetrics,
ThreadPoolMetric::getQueueSize));
+ ThreadPoolMetric threadPoolMetric =
ConcurrentHashMapUtils.computeIfAbsent(threadPoolMetricMap, name,
+ v -> new ThreadPoolMetric(collector.getApplicationName(), name,
executor));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_CORE_SIZE,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getCorePoolSize));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_LARGEST_SIZE,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getLargestPoolSize));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_MAX_SIZE,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getMaximumPoolSize));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_ACTIVE_SIZE,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getActiveCount));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_THREAD_COUNT,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getPoolSize));
+ list.add(new GaugeMetricSample<>(MetricsKey.THREAD_POOL_QUEUE_SIZE,
threadPoolMetric.getTags(), THREAD_POOL, threadPoolMetric,
ThreadPoolMetric::getQueueSize));
return list;
}