Skip to content

Commit

Permalink
Add ThreadPool#stats and adjust Server#stats to use it (#3527)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg authored Oct 26, 2024
1 parent b7e4c8c commit 2482fac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,12 @@ def shutting_down?
# Returns a hash of stats about the running server for reporting purposes.
# @version 5.0.0
# @!attribute [r] stats
# @return [Hash] hash containing stat info from `Server` and `ThreadPool`
def stats
STAT_METHODS.map {|name| [name, send(name) || 0]}.to_h
stats = @thread_pool&.stats || {}
stats[:max_threads] = @max_threads
stats[:requests_count] = @requests_count
stats
end

# below are 'delegations' to binder
Expand Down
11 changes: 11 additions & 0 deletions lib/puma/thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def self.clean_thread_locals
end
end

# generate stats hash so as not to perform multiple locks
# @return [Hash] hash containing stat info from ThreadPool
def stats
with_mutex do
{ backlog: @todo.size,
running: @spawned,
pool_capacity: @waiting + (@max - @spawned)
}
end
end

# How many objects have yet to be processed by the pool?
#
def backlog
Expand Down

0 comments on commit 2482fac

Please sign in to comment.