jetty.project
jetty.project copied to clipboard
The idle threads released very slowly from QueuedThreadPool
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?

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).
In short, Thread creation is very expensive and time consuming, so the ThreadPool is designed with that in mind.
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.
This behavior was changed by #9237, so now the thread pool is more aggressive at shrinking threads.