Executor thread number goes way above the configured pool size #32621
-
Hi, we have an app that does a poll via rest, and processes the response within a ManagedExecutor runAsync bloc. When I run something like this locally (jvm or native) I see the thread number in the log staying in the boundary of the 200 thread pool. (This run in a quartz scheduled method that runs every 3 seconds for example) for (int i = 0; i < 100000; i++) {
int idx = i;
executor.runAsync(() -> {
if (idx % 1000 == 0) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
log().info("Current index is {}", idx);
}
});
} Oddly in our production app, which the schedule method runs every 2 minutes we see the executor threads piling up, now after a few days we see something like this in the logs;
I do see something some number reuse, but still not sure why it acts this way, and for sure the processing has time to happen within the 2 minutes of the poller, versus my dummy test above where I force a 5s sleep on a 3s poll. I am afraid this will eventually blow up / hit a certain limit. For sure there are not 10k concurrent threads as our container has only 2 cpu and 256mb memory. Help would be appreciate to understand what is happening above and why this is behaving this way. I am trying to reproduce this locally but so far I an unable to. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I assume that you're using an injected This executor should indeed leverage the default blocking thread pool. So if you specify the Do you use the same value of |
Beta Was this translation helpful? Give feedback.
So after more troubleshooting and reading of the javadoc I think I understand now what is happening. To answer you question first, yes I am using
org.eclipse.microprofile.context.ManagedExecutor
, and no I am not changing this for dev/prod;quarkus.thread-pool.max-threads
.What happens is that, by default quarkus.thread-pool.core-threads is 1, meaning that a single thread stays alive forever. When the
ManagedExecutor
does multiperunAsync()
. Threads are getting created, and those thread lives idle for the configured quarkus.thread-pool.keep-alive-time once the keepalive is reached for those thread, as far as I can see, their thread number is never reused thus incrementing.Why we did not s…