jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

The idle threads released very slowly from QueuedThreadPool

Open moxiaonian opened this issue 3 years ago • 2 comments

Config:

  • Jetty version: 9.4.44.v20210927
  • Linux Server
  • idleTimeout:10000

Code: https://github.com/eclipse/jetty.project/blob/064682b4ce57282e49a80a64b6d7a7a66fb47b28/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java#L1009 Description: When a lot of threads are created at the beginning, but many are not used later. So suddenly there are a lot of idle threads. At this time, the thread queue will always be large, it will not be reduced immediately! It caused the thread count of the project to not drop for several hours. Should this variable _lastShrank be set to a thread-local variable instead of a variable shared by multiple threads?

image

moxiaonian avatar Jul 07 '22 11:07 moxiaonian

This is by design.

The idea is that if there was a spike in load that caused many threads to be allocated, likely there will be another pretty soon, so the threads will come handy.

You can be more aggressive by tuning QueuedThreadPool.idleTimeout to a shorter value, otherwise by default 1 thread is exited every 60 seconds (if it has been idle for that long).

sbordet avatar Jul 07 '22 12:07 sbordet

In short, Thread creation is very expensive and time consuming, so the ThreadPool is designed with that in mind.

joakime avatar Jul 07 '22 12:07 joakime

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 10 '23 00:07 github-actions[bot]

This behavior was changed by #9237, so now the thread pool is more aggressive at shrinking threads.

sbordet avatar Jul 10 '23 06:07 sbordet