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

Alternate worker culling strategy #2773

merged 1 commit into from Jan 1, 2022

Alternate worker culling strategy #2773

merged 1 commit into from Jan 1, 2022


Copy link


This PR adds support for an alternate worker culling strategy: instead of culling the workers at the end of the internal worker list (which in all likelihood are the most recently started workers), setting the new worker_culling_strategy configuration option to oldest will cull the workers which were started the longest time ago.

This strategy makes it easier to implement a rolling restart of workers. This would be useful for us because our workers tend to leak memory over time. While of course the right thing to do would be write good code that does not leak memory :D in practice it's very hard and replacing workers every so often is a cheap and easy strategy.

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

Comment on lines -125 to +135
all_positions = 0...@options[:workers]
occupied_positions = { |w| w.index }
available_positions = all_positions.to_a - occupied_positions
occupied_positions =
idx = 0
idx += 1 until !occupied_positions.include?(idx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I changed this method's implementation is because I ran into an edge case while writing tests for this PR: if @options[:workers] is decreased (e.g. because the process received a TTOU signal), the previous implementation could potentially return nil.

lib/puma/dsl.rb Outdated Show resolved Hide resolved
Copy link
Contributor Author

Renamed default to youngest as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

4 participants