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

Limit ReservedThread creation

Open sbordet opened this issue 2 months ago • 7 comments

Jetty version(s) 12.1.x

Description If all the threads of a thread pool are taken, and a new request arrives, the job to handle the request is queued, but also the task for a new ReservedThread.

We should count how many pending ReservedThread we attempted to start, and stop when we reach the capacity, to avoid to continuously queue ReservedThread tasks to the thread pool.

A dump showed ~2700 tasks for ReservedThread, which is obviously much more than the ReservedThreadExecutor capacity.

sbordet avatar Oct 13 '25 15:10 sbordet

Hello, Do you need help with this issue? I can support it.

arsenalzp avatar Oct 14 '25 14:10 arsenalzp

@arsenalzp yes, can you spot the problem? Let's discuss it in this issue.

sbordet avatar Oct 14 '25 15:10 sbordet

@arsenalzp yes, can you spot the problem? Let's discuss it in this issue.

Hello, Superficially, I understand the meaning of this issue. It is necessary to deep dive into the code.

arsenalzp avatar Oct 16 '25 22:10 arsenalzp

Ah! We recently removed the accounting for pending threads as we thought it was unnecessary. Obviously not!

If you look back a few tries you will see what we used to do. Maybe we just restore that, or maybe there is something better we can do?

gregw avatar Oct 16 '25 22:10 gregw

@gregw this is ReservedThreadExecutor and it still has accounting for pending threads.

However, the default is that we have no limit for maxPending, while I think a better default should the capacity.

Given that maxPending=-1 means "unlimited", we can use 0 (currently an invalid value) to mean "default", and we default at capacity.

Because also capacity can be negative (meaning "heuristic"), we need to re-compute maxPending in the constructor with the effective value of capacity.

@arsenalzp can you implement the above in a PR?

sbordet avatar Oct 17 '25 16:10 sbordet

@arsenalzp can you implement the above in a PR?

Hello, Let's try it. What is the ultimate term for this improvement?

arsenalzp avatar Oct 20 '25 11:10 arsenalzp

@arsenalzp the change should be simple, end of month we have a scheduled release, but this issue is not urgent.

sbordet avatar Oct 21 '25 20:10 sbordet