summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/handler
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-10-15 09:41:57 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2021-10-15 09:41:57 +0200
commit3e2d55524104f071acca940abbc554142b8a5481 (patch)
tree783caea7c7220e4befdc9c6cce3c6978b8475d63 /container-core/src/main/java/com/yahoo/container/handler
parent5f8e1a37f9b0cbf04eb9a008aac17bf1d80cbf45 (diff)
Metrics Q size and capacity must into account what kind of Q is used.
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/handler')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/threadpool/ExecutorServiceWrapper.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ExecutorServiceWrapper.java b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ExecutorServiceWrapper.java
index 5ba5985db37..99f49f10526 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ExecutorServiceWrapper.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ExecutorServiceWrapper.java
@@ -26,6 +26,7 @@ class ExecutorServiceWrapper extends ForwardingExecutorService {
private final long maxThreadExecutionTimeMillis;
private final int queueCapacity;
private final Thread metricReporter;
+ private final boolean threadPoolIsOnlyQ;
private final AtomicBoolean closed = new AtomicBoolean(false);
ExecutorServiceWrapper(WorkerCompletionTimingThreadPoolExecutor wrapped,
@@ -37,21 +38,32 @@ class ExecutorServiceWrapper extends ForwardingExecutorService {
this.metric = metric;
this.processTerminator = processTerminator;
this.maxThreadExecutionTimeMillis = maxThreadExecutionTimeMillis;
- this.queueCapacity = wrapped.getMaximumPoolSize() + wrapped.getQueue().remainingCapacity() + wrapped.getQueue().size();
+ int maxQueueCapacity = wrapped.getQueue().remainingCapacity() + wrapped.getQueue().size();
+ this.threadPoolIsOnlyQ = (maxQueueCapacity == 0);
+ this.queueCapacity = threadPoolIsOnlyQ
+ ? wrapped.getMaximumPoolSize()
+ : maxQueueCapacity;
metric.reportThreadPoolSize(wrapped.getPoolSize());
metric.reportActiveThreads(wrapped.getActiveCount());
- metricReporter = new Thread(this::reportMetrics);
+ reportMetrics();
+ metricReporter = new Thread(this::reportMetricsRegularly);
metricReporter.setName(name + "-threadpool-metric-reporter");
metricReporter.start();
}
private void reportMetrics() {
+ int activeThreads = wrapped.getActiveCount();
+ metric.reportThreadPoolSize(wrapped.getPoolSize());
+ metric.reportActiveThreads(activeThreads);
+ int queueSize = threadPoolIsOnlyQ ? activeThreads : wrapped.getQueue().size();
+ metric.reportWorkQueueSize(queueSize);
+ metric.reportWorkQueueCapacity(queueCapacity);
+ }
+
+ private void reportMetricsRegularly() {
while (timeToReportMetricsAgain(100)) {
- metric.reportThreadPoolSize(wrapped.getPoolSize());
- metric.reportActiveThreads(wrapped.getActiveCount());
- metric.reportWorkQueueSize(wrapped.getQueue().size());
- metric.reportWorkQueueCapacity(queueCapacity);
+ reportMetrics();
}
}
private boolean timeToReportMetricsAgain(int timeoutMS) {