Skip to content

Commit

Permalink
Restore automatic detection of processor count in default puma config
Browse files Browse the repository at this point in the history
It has to be reverted because the previous implementation wasn't
cgroup aware so it would often start way too many processes on various
shared hosting platforms.

Thanks to ruby-concurrency/concurrent-ruby#1038
concurrent-ruby 1.3 now offer a cgroups aware method to detect how
many processors we can actually use.
  • Loading branch information
byroot authored and xjunior committed Jun 9, 2024
1 parent a1f46ff commit 579bf83
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ PATH
activesupport (8.0.0.alpha)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
Expand Down Expand Up @@ -182,7 +182,7 @@ GEM
cgi (0.4.1)
chef-utils (18.3.0)
concurrent-ruby
concurrent-ruby (1.2.2)
concurrent-ruby (1.3.1)
connection_pool (2.4.1)
crack (0.4.5)
rexml
Expand Down
2 changes: 1 addition & 1 deletion activesupport/activesupport.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Gem::Specification.new do |s|

s.add_dependency "i18n", ">= 1.6", "< 2"
s.add_dependency "tzinfo", "~> 2.0", ">= 2.0.5"
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.3.1"
s.add_dependency "connection_pool", ">= 2.2.5"
s.add_dependency "minitest", ">= 5.1"
s.add_dependency "base64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ when "production"
# If you are running more than 1 thread per process, the workers count
# should be equal to the number of processors (CPU cores) in production.
#
# It defaults to 1 because it's impossible to reliably detect how many
# CPU cores are available. Make sure to set the `WEB_CONCURRENCY` environment
# variable to match the number of processors.
workers_count = Integer(ENV.fetch("WEB_CONCURRENCY", 1))
# Automatically detect the number of available processors in production.
require "concurrent-ruby"
workers_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.available_processor_count })
workers workers_count if workers_count > 1

preload_app!
Expand Down

0 comments on commit 579bf83

Please sign in to comment.