quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Metrics for main thread pool (executor-thread) #37729

Open ynojima opened 8 months ago

ynojima commented 8 months ago

Description

In my understanding, blocking tasks are executed with main thread pool (executor-thread), not with vert-x thread pool (vert.x-worker-thread) from quarkus 1.1.0.Final. https://github.com/quarkusio/quarkus/pull/6217

resteasy(-classic) resource log indicates it is executed with executor-thread-<n>.

2023-12-14 11:12:56,583 INFO  [com.red.gss.GreetingResource] (executor-thread-0) Hello from resteasy(-classic) resource

But Micrometer only emits worker_pool metrics for vert.x-internal-blocking and vert.x-worker-thread.

$ curl -s http://localhost:8080/q/metrics | grep worker_pool_active
# TYPE worker_pool_active gauge
# HELP worker_pool_active The number of resources from the pool currently used
worker_pool_active{pool_name="vert.x-internal-blocking",pool_type="worker"} 0.0
worker_pool_active{pool_name="vert.x-worker-thread",pool_type="worker"} 1.0

We should have metrics for the main thread pool (executor-thread) too.

Implementation ideas

No response

quarkus-bot[bot] commented 8 months ago

/cc @ebullient (metrics), @jmartisk (metrics)

bh-tt commented 1 month ago

I think a possible implementation plan is to change https://github.com/quarkusio/quarkus/blob/6f8c261711e36462497254436f216efb926b7119/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java#L106 to use a proxy executor for the smallrye executor, which then submits proxy tasks to smallrye to allow timing when these tasks are started and finished. That is the information needed to provide useful metrics for this pool. This would of course only be the case if a metrics extension is present.

I'd be willing to implement this (our company had some issues with the main thread pool filling up and we'd like to monitor this), if I get a greenlight from @ebullient or @jmartisk that the above setup would be good implementation.

dmlloyd commented 1 month ago

If you want to monitor the duration of tasks, then a proxy executor does seem like the way to go, however it might be best to do this at the lowest level (wrap the EnhancedQueueExecutor directly) rather than above SmallRye.

There are some other metrics that are already readily available on the EnhancedQueueExecutor API which might be of use as well.