Skip to content

Commit 37f88fa

Browse files
authored
Update Jetty thread pool metrics (#18883)
Add new Jetty thread pool metrics to capture request-serving thread statistics: jetty/threadPool/utilized, jetty/threadPool/ready and jetty/threadPool/utilizationRate. Unlike some of the existing metrics, these new metrics are intended to serve as an indicator for threads that would serve requests from the thread pool. Also update the documentation for the new metrics and also fixes up descriptions for some existing Jetty metrics.
1 parent 3f2048b commit 37f88fa

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

docs/operations/metrics.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ to represent the task ID are deprecated and will be removed in a future release.
149149
|Metric|Description|Normal value|
150150
|------|-----------|------------|
151151
|`jetty/numOpenConnections`|Number of open jetty connections.|Not much higher than number of jetty threads.|
152-
|`jetty/threadPool/total`|Number of total workable threads allocated.|The number should equal to `threadPoolNumIdleThreads` + `threadPoolNumBusyThreads`.|
153-
|`jetty/threadPool/idle`|Number of idle threads.|Less than or equal to `threadPoolNumTotalThreads`. Non zero number means there is less work to do than configured capacity.|
154-
|`jetty/threadPool/busy`|Number of busy threads that has work to do from the worker queue.|Less than or equal to `threadPoolNumTotalThreads`.|
155-
|`jetty/threadPool/isLowOnThreads`|A rough indicator of whether number of total workable threads allocated is enough to handle the works in the work queue.|0|
152+
|`jetty/threadPool/total`|Number of total threads allocated. This includes internal threads and threads that are ready to serve requests.|Equals the total number of threads in the Jetty thread pool. i.e., `jetty/threadPool/ready` + `jetty/threadPool/utilized` + any reserved threads for internal Jetty usage.|
153+
|`jetty/threadPool/ready`|Number of threads that are ready to serve requests.|Equals the total number of usable threads in the Jetty thread pool to serve requests. i.e., `jetty/threadPool/idle` + any reserved threads for internal Jetty usage.|
154+
|`jetty/threadPool/utilized`|Number of threads currently in use by the thread pool to serve requests.|Value < `jetty/threadPool/ready`.|
155+
|`jetty/threadPool/utilizationRate`|Fraction of thread pool capacity currently in use to serve requests.|0.0 ≤ Value ≤ 1. A value of 0.0 means that the thread pool is not utilized, while a value of 1.0 means that the thread pool is fully utilized.|
156+
|`jetty/threadPool/idle`|Number of idle threads.|Value ≤ (`jetty/threadPool/ready` - any reserved threads for internal Jetty usage). A non-zero value means there is less work to do than configured capacity.|
157+
|`jetty/threadPool/busy`|Number of busy threads that have work to do from the worker queue.|Value ≤ (`jetty/threadPool/utilized` + any reserved threads for internal Jetty usage).|
158+
|`jetty/threadPool/isLowOnThreads`|A rough indicator of whether the number of total workable threads allocated is enough to handle the work in the work queue.|0|
156159
|`jetty/threadPool/min`|Number of minimum threads allocatable.|`druid.server.http.numThreads` plus a small fixed number of threads allocated for Jetty acceptors and selectors.|
157160
|`jetty/threadPool/max`|Number of maximum threads allocatable.|`druid.server.http.numThreads` plus a small fixed number of threads allocated for Jetty acceptors and selectors.|
158161
|`jetty/threadPool/queueSize`|Size of the worker queue.|Not much higher than `druid.server.http.queueSize`.|

extensions-contrib/opentsdb-emitter/src/main/resources/defaultMetrics.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
],
3030
"jetty/numOpenConnections": [],
3131
"jetty/threadPool/total": [],
32+
"jetty/threadPool/ready": [],
33+
"jetty/threadPool/utilized": [],
34+
"jetty/threadPool/utilizationRate": [],
3235
"jetty/threadPool/idle": [],
3336
"jetty/threadPool/busy": [],
3437
"jetty/threadPool/isLowOnThreads": [],

extensions-contrib/prometheus-emitter/src/main/resources/defaultMetrics.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
"jetty/numOpenConnections" : { "dimensions" : [], "type" : "gauge", "help": "Number of open jetty connections."},
3939
"jetty/threadPool/total" : { "dimensions" : [], "type" : "gauge", "help": "Number of total workable threads allocated."},
40+
"jetty/threadPool/ready" : { "dimensions" : [], "type" : "gauge", "help": "Number of threads that are ready to serve requests."},
41+
"jetty/threadPool/utilized" : { "dimensions" : [], "type" : "gauge", "help": "Number of threads currently in use to serve requests."},
42+
"jetty/threadPool/utilizationRate" : { "dimensions" : [], "type" : "gauge", "help": "Fraction of thread pool capacity currently in use to serve requests."},
4043
"jetty/threadPool/idle" : { "dimensions" : [], "type" : "gauge", "help": "Number of idle threads."},
4144
"jetty/threadPool/busy" : { "dimensions" : [], "type" : "gauge", "help": "Number of busy threads that has work to do from the worker queue."},
4245
"jetty/threadPool/isLowOnThreads" : { "dimensions" : [], "type" : "gauge", "help": "A rough indicator of whether number of total workable threads allocated is enough to handle the works in the work queue."},

extensions-contrib/statsd-emitter/src/main/resources/defaultMetricDimensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@
159159

160160
"jetty/numOpenConnections": { "dimensions" : [], "type" : "gauge" },
161161
"jetty/threadPool/total": { "dimensions" : [], "type" : "gauge" },
162+
"jetty/threadPool/ready": { "dimensions" : [], "type" : "gauge" },
163+
"jetty/threadPool/utilized": { "dimensions" : [], "type" : "gauge" },
164+
"jetty/threadPool/utilizationRate": { "dimensions" : [], "type" : "gauge" },
162165
"jetty/threadPool/idle": { "dimensions" : [], "type" : "gauge" },
163166
"jetty/threadPool/busy": { "dimensions" : [], "type" : "gauge" },
164167
"jetty/threadPool/isLowOnThreads": { "dimensions" : [], "type" : "gauge" },

server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ public boolean doMonitor(ServiceEmitter emitter)
528528
if (jettyServerThreadPool != null) {
529529
emitter.emit(builder.setMetric("jetty/threadPool/total", jettyServerThreadPool.getThreads()));
530530
emitter.emit(builder.setMetric("jetty/threadPool/idle", jettyServerThreadPool.getIdleThreads()));
531+
532+
emitter.emit(builder.setMetric("jetty/threadPool/ready", jettyServerThreadPool.getReadyThreads()));
533+
emitter.emit(builder.setMetric("jetty/threadPool/utilized", jettyServerThreadPool.getUtilizedThreads()));
534+
emitter.emit(builder.setMetric("jetty/threadPool/utilizationRate", jettyServerThreadPool.getUtilizationRate()));
535+
531536
emitter.emit(builder.setMetric("jetty/threadPool/isLowOnThreads", jettyServerThreadPool.isLowOnThreads() ? 1 : 0));
532537
emitter.emit(builder.setMetric("jetty/threadPool/min", jettyServerThreadPool.getMinThreads()));
533538
emitter.emit(builder.setMetric("jetty/threadPool/max", jettyServerThreadPool.getMaxThreads()));

server/src/test/java/org/apache/druid/server/initialization/jetty/JettyServerModuleTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public void testJettyServerModule()
5353
Mockito.when(jettyServerThreadPool.getMaxThreads()).thenReturn(100);
5454
Mockito.when(jettyServerThreadPool.getQueueSize()).thenReturn(50);
5555
Mockito.when(jettyServerThreadPool.getBusyThreads()).thenReturn(60);
56+
Mockito.when(jettyServerThreadPool.getReadyThreads()).thenReturn(20);
57+
Mockito.when(jettyServerThreadPool.getUtilizedThreads()).thenReturn(5);
58+
Mockito.when(jettyServerThreadPool.getUtilizationRate()).thenReturn(0.45);
5659

5760
JettyServerModule.JettyMonitor jettyMonitor = new JettyServerModule.JettyMonitor();
5861

@@ -67,6 +70,9 @@ public void testJettyServerModule()
6770
serviceEmitter.verifyValue("jetty/threadPool/max", 100);
6871
serviceEmitter.verifyValue("jetty/threadPool/queueSize", 50);
6972
serviceEmitter.verifyValue("jetty/threadPool/busy", 60);
73+
serviceEmitter.verifyValue("jetty/threadPool/ready", 20);
74+
serviceEmitter.verifyValue("jetty/threadPool/utilized", 5);
75+
serviceEmitter.verifyValue("jetty/threadPool/utilizationRate", 0.45);
7076
}
7177

7278
@Test

0 commit comments

Comments
 (0)