mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
[close #1577] Negative Backpressure Metric
This PR introduces the `pool_capacity` stat which can be used as a “negative back pressure metric”. What does a “negative backpressure metric” mean? It means when this number is low, we have a higher amount of backpressure. When it is zero it means that our worker has no ability to process additional requests. This information could be used to scale out by adding additional servers. When that happens the requests should be re-distributed between the extra server and the “pool capacity” number for each individual server should go up.
This commit is contained in:
parent
119b6eb4ad
commit
8b10df8b2b
4 changed files with 10 additions and 3 deletions
|
@ -292,7 +292,8 @@ module Puma
|
|||
begin
|
||||
b = server.backlog || 0
|
||||
r = server.running || 0
|
||||
payload = %Q!#{base_payload}{ "backlog":#{b}, "running":#{r} }\n!
|
||||
t = server.pool_capacity || 0
|
||||
payload = %Q!#{base_payload}{ "backlog":#{b}, "running":#{r}, "pool_capacity": #{t} }\n!
|
||||
io << payload
|
||||
rescue IOError
|
||||
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
|
||||
|
|
|
@ -168,6 +168,11 @@ module Puma
|
|||
@thread_pool and @thread_pool.spawned
|
||||
end
|
||||
|
||||
|
||||
def pool_capacity
|
||||
@thread_pool and @thread_pool.waiting
|
||||
end
|
||||
|
||||
# Lopez Mode == raw tcp apps
|
||||
|
||||
def run_lopez_mode(background=true)
|
||||
|
|
|
@ -14,7 +14,8 @@ module Puma
|
|||
def stats
|
||||
b = @server.backlog || 0
|
||||
r = @server.running || 0
|
||||
%Q!{ "backlog": #{b}, "running": #{r} }!
|
||||
t = @server.pool_capacity || 0
|
||||
%Q!{ "backlog": #{b}, "running": #{r}, "pool_capacity": #{t} }!
|
||||
end
|
||||
|
||||
def restart
|
||||
|
|
|
@ -58,7 +58,7 @@ module Puma
|
|||
@clean_thread_locals = false
|
||||
end
|
||||
|
||||
attr_reader :spawned, :trim_requested
|
||||
attr_reader :spawned, :trim_requested, :waiting
|
||||
attr_accessor :clean_thread_locals
|
||||
|
||||
def self.clean_thread_locals
|
||||
|
|
Loading…
Reference in a new issue