1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Meter calling accept(2) with available pool capacity (#1278)

* Meter calling accept(2) with available pool capacity

Talking through this with Nate and Richard, we realized that accepting
new clients without taking account for the available capacity of the
thread pool doesn't improve throughput, it only hurts it in the case of
multiple workers. If a worker pauses (or starts up before other
workers), then a worker can accidentally suck up a high number of
clients and leave unused capacity inside the other workers.

This change will smooth out this issue, with a minor penalty to maximum
throughput.

* Rewrite the conditional to be less confusing
This commit is contained in:
Evan Phoenix 2017-04-28 10:42:09 -07:00 committed by Nate Berkopec
parent 5aa67ca29a
commit 482ea5a24a
2 changed files with 10 additions and 2 deletions

View file

@ -363,7 +363,7 @@ module Puma
end
pool << client
pool.wait_until_not_full unless queue_requests
pool.wait_until_not_full
end
rescue SystemCallError
# nothing

View file

@ -155,7 +155,15 @@ module Puma
def wait_until_not_full
@mutex.synchronize do
until @todo.size - @waiting < @max - @spawned or @shutdown
while true
return if @shutdown
return if @waiting > 0
# If we can still spin up new threads and there
# is work queued, then accept more work until we would
# spin up the max number of threads.
return if @todo.size < @max - @spawned
@not_full.wait @mutex
end
end