Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set worker thread name. #974

Merged
merged 2 commits into from May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Manifest.txt
Expand Up @@ -8,7 +8,6 @@ Rakefile
bin/puma
bin/puma-wild
bin/pumactl
docs/config.md
docs/nginx.md
docs/signals.md
docs/systemd.md
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/thread_pool.rb
Expand Up @@ -68,6 +68,8 @@ def spawn_thread
@spawned += 1

th = Thread.new do
# Thread name is new in Ruby 2.3
Thread.current.name = 'puma %03i' % @spawned if Thread.current.respond_to?(:name=)
todo = @todo
block = @block
mutex = @mutex
Expand Down
4 changes: 4 additions & 0 deletions test/test_thread_pool.rb
Expand Up @@ -19,9 +19,11 @@ def pause

def test_append_spawns
saw = []
thread_name = nil

pool = new_pool(0, 1) do |work|
saw << work
thread_name = Thread.current.name if Thread.current.respond_to?(:name)
end

pool << 1
Expand All @@ -30,6 +32,8 @@ def test_append_spawns

assert_equal [1], saw
assert_equal 1, pool.spawned
# Thread name is new in Ruby 2.3
assert_equal('puma 001', thread_name) if Thread.current.respond_to?(:name)
end

def test_converts_pool_sizes
Expand Down