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

All Puma threads are named (#1968)

This commit is contained in:
Nate Berkopec 2019-09-15 10:52:34 +02:00 committed by GitHub
parent 92ec65b201
commit efb1dbfd71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 7 deletions

View file

@ -22,4 +22,10 @@ module Puma
def self.stats
@get_stats.stats
end
# Thread name is new in Ruby 2.3
def self.set_thread_name(name)
return unless Thread.current.respond_to?(:name=)
Thread.current.name = "puma #{name}"
end
end

View file

@ -248,6 +248,7 @@ module Puma
@suicide_pipe.close
Thread.new do
Puma.set_thread_name "worker check pipe"
IO.select [@check_pipe]
log "! Detected parent died, dying"
exit! 1
@ -282,6 +283,7 @@ module Puma
end
Thread.new(@worker_write) do |io|
Puma.set_thread_name "stat payload"
base_payload = "p#{Process.pid}"
while true

View file

@ -328,6 +328,10 @@ module Puma
def log_thread_status
Thread.list.each do |thread|
@events.log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
logstr = "Thread: TID-#{thread.object_id.to_s(36)}"
logstr += " #{thread.name}" if thread.respond_to?(:name)
@events.log logstr
if thread.backtrace
@events.log thread.backtrace.join("\n")
else

View file

@ -63,7 +63,10 @@ module Puma
def fire_background
@background.each do |b|
Thread.new(&b)
Thread.new do
set_thread_name "plugin background"
b.call
end
end
end
end

View file

@ -307,6 +307,7 @@ module Puma
def run_in_thread
@thread = Thread.new do
Puma.set_thread_name "reactor"
begin
run_internal
rescue StandardError => e

View file

@ -207,7 +207,10 @@ module Puma
@events.fire :state, :running
if background
@thread = Thread.new { handle_servers_lopez_mode }
@thread = Thread.new do
Puma.set_thread_name "server"
handle_servers_lopez_mode
end
return @thread
else
handle_servers_lopez_mode
@ -351,7 +354,10 @@ module Puma
@events.fire :state, :running
if background
@thread = Thread.new { handle_servers }
@thread = Thread.new do
Puma.set_thread_name "server"
handle_servers
end
return @thread
else
handle_servers

View file

@ -87,8 +87,7 @@ module Puma
@spawned += 1
th = Thread.new(@spawned) do |spawned|
# Thread name is new in Ruby 2.3
Thread.current.name = 'puma %03i' % spawned if Thread.current.respond_to?(:name=)
Puma.set_thread_name 'threadpool %03i' % spawned
todo = @todo
block = @block
mutex = @mutex
@ -255,6 +254,7 @@ module Puma
@running = true
@thread = Thread.new do
Puma.set_thread_name "threadpool autotrim"
while @running
@pool.trim
sleep @timeout
@ -284,6 +284,7 @@ module Puma
@running = true
@thread = Thread.new do
Puma.set_thread_name "threadpool reaper"
while @running
@pool.reap
sleep @timeout

View file

@ -4,7 +4,7 @@ require_relative "helpers/integration"
class TestIntegrationCluster < TestIntegration
def setup
super
skip NO_FORK_MSG unless HAS_FORK
end

View file

@ -37,7 +37,7 @@ class TestThreadPool < Minitest::Test
@work_done.wait(@work_mutex, 5)
assert_equal 1, pool.spawned
assert_equal [1], saw
assert_equal('puma 001', thread_name) if Thread.current.respond_to?(:name)
assert_equal('puma threadpool 001', thread_name) if Thread.current.respond_to?(:name)
end
end