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

Minor refactor on Thread pool #1088

Merged
merged 3 commits into from
Nov 20, 2016
Merged

Minor refactor on Thread pool #1088

merged 3 commits into from
Nov 20, 2016

Conversation

frodsan
Copy link
Contributor

@frodsan frodsan commented Sep 10, 2016

  • Puma::Threadpool uses only one constant from the constants file. At the beginning, I was thinking to add the missing require to const.rb to the ThreadPool, but I think it's better to just move the constant to where it's used.
  • I removed the check for timeout == 0 since the times block will not be executed if it's zero.

Francesco Rodriguez added 3 commits September 10, 2016 14:49
SHUTDOWN_GRACE_TIME is the only constant (from const.rb) used by
ThreadPool. It's better to move the constant than require all const.rb.
This removes the duplicated code and add test for forced shutdowns.
@evanphx
Copy link
Member

evanphx commented Sep 17, 2016

I believe this is wrong because it remove the call to Thread#raise when 0 is used.

@frodsan
Copy link
Contributor Author

frodsan commented Sep 18, 2016

This is the code now:

when 0
  threads.each do |t|
    t.raise ForceShutdown
  end

  threads.each do |t|
    t.join SHUTDOWN_GRACE_TIME
  end
else
  timeout.times do
    # ...
  end

  threads.each do |t|
    t.raise ForceShutdown
  end

  threads.each do |t|
    t.join SHUTDOWN_GRACE_TIME
  end
end

And this is the proposed change:

else
  # If timeout is `0`, it will skip this part,
  # and raise (force shutdown) immediately
  timeout.times do
    # ...
  end

  threads.each do |t|
    t.raise ForceShutdown
  end

  threads.each do |t|
    t.join SHUTDOWN_GRACE_TIME
  end
end

I think in both scenarios #raise is called, when timeout is equal or greater than 0.

@nateberkopec
Copy link
Member

Makes sense to me - clever use of 0.times.

@nateberkopec nateberkopec merged commit 64f930d into puma:master Nov 20, 2016
@frodsan frodsan deleted the refactor-thread-pool branch November 20, 2016 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants