diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-09-17 16:06:30 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-09-22 15:03:42 +0200 |
commit | 449dbcad01d0b18531b0a2707e933cbbe60733d8 (patch) | |
tree | ff16f3ab76ae63f35de6b549300a4a0ca514d7c3 /container-core | |
parent | a4621d00adcc2fd6ece64b0ecacff05d3d20e67b (diff) |
Add metrics for the threadpool's work queue
Diffstat (limited to 'container-core')
3 files changed, 10 insertions, 5 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/threadpool/DefaultContainerThreadpool.java b/container-core/src/main/java/com/yahoo/container/handler/threadpool/DefaultContainerThreadpool.java index 4d8c245a25a..46b3a86798b 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/threadpool/DefaultContainerThreadpool.java +++ b/container-core/src/main/java/com/yahoo/container/handler/threadpool/DefaultContainerThreadpool.java @@ -44,8 +44,9 @@ public class DefaultContainerThreadpool extends AbstractComponent implements Aut // get the dreaded thread locals initialized even if they will never run. // That counters what we we want to achieve with the Q that will prefer thread locality. executor.prestartAllCoreThreads(); - threadpool = new ExecutorServiceWrapper(executor, threadPoolMetric, processTerminator, - config.maxThreadExecutionTimeSeconds() * 1000L); + threadpool = new ExecutorServiceWrapper( + executor, threadPoolMetric, processTerminator, config.maxThreadExecutionTimeSeconds() * 1000L, + config.name(), config.queueSize()); } @Override public Executor executor() { return threadpool; } 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 3b2b5697e5c..771c1da82b6 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 @@ -24,17 +24,19 @@ class ExecutorServiceWrapper extends ForwardingExecutorService { private final ThreadPoolMetric metric; private final ProcessTerminator processTerminator; private final long maxThreadExecutionTimeMillis; + private final int queueCapacity; private final Thread metricReporter; private final AtomicBoolean closed = new AtomicBoolean(false); ExecutorServiceWrapper( WorkerCompletionTimingThreadPoolExecutor wrapped, ThreadPoolMetric metric, ProcessTerminator processTerminator, - long maxThreadExecutionTimeMillis, String name) { + long maxThreadExecutionTimeMillis, String name, int queueCapacity) { this.wrapped = wrapped; this.metric = metric; this.processTerminator = processTerminator; this.maxThreadExecutionTimeMillis = maxThreadExecutionTimeMillis; + this.queueCapacity = queueCapacity; metric.reportThreadPoolSize(wrapped.getPoolSize()); metric.reportActiveThreads(wrapped.getActiveCount()); @@ -44,13 +46,13 @@ class ExecutorServiceWrapper extends ForwardingExecutorService { metricReporter.start(); } - int queuedTasks() { return wrapped.getQueue().size(); } - private void reportMetrics() { try { while (!closed.get()) { metric.reportThreadPoolSize(wrapped.getPoolSize()); metric.reportActiveThreads(wrapped.getActiveCount()); + metric.reportWorkQueueSize(wrapped.getQueue().size()); + metric.reportWorkQueueCapacity(queueCapacity); Thread.sleep(100); } } catch (InterruptedException e) { } diff --git a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ThreadPoolMetric.java b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ThreadPoolMetric.java index d9ab020bcb8..18ccf3ba8e5 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/threadpool/ThreadPoolMetric.java +++ b/container-core/src/main/java/com/yahoo/container/handler/threadpool/ThreadPoolMetric.java @@ -25,6 +25,8 @@ class ThreadPoolMetric { void reportRejectRequest() { metric.add("serverRejectedRequests", 1L, defaultContext); } void reportThreadPoolSize(long size) { metric.set("serverThreadPoolSize", size, defaultContext); } void reportActiveThreads(long threads) { metric.set("serverActiveThreads", threads, defaultContext); } + void reportWorkQueueCapacity(long capacity) { metric.set("jdisc.thread_pool.work_queue.capacity", capacity, defaultContext); } + void reportWorkQueueSize(long size) { metric.set("jdisc.thread_pool.work_queue.size", size, defaultContext); } void reportUnhandledException(Throwable t) { Metric.Context ctx = metric.createContext(Map.of( THREAD_POOL_NAME_DIMENSION, threadPoolName, |