Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The idle threads released very slowly from QueuedThreadPool #8270

Closed
moxiaonian opened this issue Jul 7, 2022 · 4 comments
Closed

The idle threads released very slowly from QueuedThreadPool #8270

moxiaonian opened this issue Jul 7, 2022 · 4 comments
Labels
Question Stale For auto-closed stale issues and pull requests

Comments

@moxiaonian
Copy link

moxiaonian commented Jul 7, 2022

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

@sbordet
Copy link
Contributor

sbordet commented Jul 7, 2022

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).

@joakime
Copy link
Contributor

joakime commented Jul 7, 2022

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

@joakime joakime changed the title The idle threads released very slowly ! The idle threads released very slowly from QueuedThreadPool Jul 9, 2022
@github-actions
Copy link

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 github-actions bot added the Stale For auto-closed stale issues and pull requests label Jul 10, 2023
@sbordet
Copy link
Contributor

sbordet commented Jul 10, 2023

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

@sbordet sbordet closed this as completed Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Stale For auto-closed stale issues and pull requests
Projects
None yet
Development

No branches or pull requests

3 participants