siddharthteotia commented on code in PR #15716:
URL: https://github.com/apache/pinot/pull/15716#discussion_r2078956881
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java:
##########
@@ -130,4 +140,54 @@ public void filter(ContainerRequestContext
containerRequestContext,
public HttpServer getHttpServer() {
return _httpServer;
}
+
+ /**
+ * Registers a gauge that tracks HTTP thread pool utilization without using
reflection.
+ * Instead, it uses a custom ThreadPoolProbe to count active threads.
+ */
+ public void registerHttpThreadUtilizationGauge(ControllerMetrics metrics) {
+ NetworkListener listener = _httpServer.getListeners().iterator().next();
+ ExecutorService executor = listener.getTransport().getWorkerThreadPool();
+ ThreadPoolConfig poolCfg =
listener.getTransport().getWorkerThreadPoolConfig();
+
+ ActiveThreadProbe probe = new ActiveThreadProbe();
+ // Try to attach probe to the executor if it supports monitoring
+ if (executor instanceof MonitoringAware) {
+ @SuppressWarnings("unchecked")
+ MonitoringConfig<ThreadPoolProbe> mc =
((MonitoringAware<ThreadPoolProbe>) executor).getMonitoringConfig();
+ mc.addProbes(probe);
+ }
+
+
metrics.setOrUpdateGauge(ControllerGauge.HTTP_THREAD_UTILIZATION_PERCENT.getGaugeName(),
() -> {
+ int max = poolCfg.getMaxPoolSize();
+ if (max <= 0) {
+ return 0L;
+ }
+ return Math.round(probe.getActiveCount() * 100.0 / max);
+ });
+ }
+
+ /**
+ * Custom probe to track busy threads in Grizzly thread pools without using
reflection.
+ */
+ public static final class ActiveThreadProbe extends ThreadPoolProbe.Adapter {
Review Comment:
Doesn't JVM natively provide a standard way / coding idiom of measuring
thread utilization ? Do we necessarily implement all of this ?
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java:
##########
@@ -130,4 +140,54 @@ public void filter(ContainerRequestContext
containerRequestContext,
public HttpServer getHttpServer() {
return _httpServer;
}
+
+ /**
+ * Registers a gauge that tracks HTTP thread pool utilization without using
reflection.
+ * Instead, it uses a custom ThreadPoolProbe to count active threads.
+ */
+ public void registerHttpThreadUtilizationGauge(ControllerMetrics metrics) {
+ NetworkListener listener = _httpServer.getListeners().iterator().next();
+ ExecutorService executor = listener.getTransport().getWorkerThreadPool();
+ ThreadPoolConfig poolCfg =
listener.getTransport().getWorkerThreadPoolConfig();
+
+ ActiveThreadProbe probe = new ActiveThreadProbe();
+ // Try to attach probe to the executor if it supports monitoring
+ if (executor instanceof MonitoringAware) {
+ @SuppressWarnings("unchecked")
+ MonitoringConfig<ThreadPoolProbe> mc =
((MonitoringAware<ThreadPoolProbe>) executor).getMonitoringConfig();
+ mc.addProbes(probe);
+ }
+
+
metrics.setOrUpdateGauge(ControllerGauge.HTTP_THREAD_UTILIZATION_PERCENT.getGaugeName(),
() -> {
+ int max = poolCfg.getMaxPoolSize();
+ if (max <= 0) {
+ return 0L;
+ }
+ return Math.round(probe.getActiveCount() * 100.0 / max);
+ });
+ }
+
+ /**
+ * Custom probe to track busy threads in Grizzly thread pools without using
reflection.
+ */
+ public static final class ActiveThreadProbe extends ThreadPoolProbe.Adapter {
Review Comment:
Doesn't JVM natively provide a standard way / coding idiom of measuring
thread utilization ? Do we necessarily have to implement all of this ?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]