Skip to content

Commit f719787

Browse files
committed
Restore automatic detection of processor count in default puma config
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.
1 parent 23bf7b6 commit f719787

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ PATH
8989
activesupport (8.0.0.alpha)
9090
base64
9191
bigdecimal
92-
concurrent-ruby (~> 1.0, >= 1.0.2)
92+
concurrent-ruby (~> 1.0, >= 1.3.1)
9393
connection_pool (>= 2.2.5)
9494
drb
9595
i18n (>= 1.6, < 2)
@@ -182,7 +182,7 @@ GEM
182182
cgi (0.4.1)
183183
chef-utils (18.3.0)
184184
concurrent-ruby
185-
concurrent-ruby (1.2.2)
185+
concurrent-ruby (1.3.1)
186186
connection_pool (2.4.1)
187187
crack (0.4.5)
188188
rexml

activesupport/activesupport.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
3636

3737
s.add_dependency "i18n", ">= 1.6", "< 2"
3838
s.add_dependency "tzinfo", "~> 2.0", ">= 2.0.5"
39-
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
39+
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.3.1"
4040
s.add_dependency "connection_pool", ">= 2.2.5"
4141
s.add_dependency "minitest", ">= 5.1"
4242
s.add_dependency "base64"

railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ when "production"
3232
# If you are running more than 1 thread per process, the workers count
3333
# should be equal to the number of processors (CPU cores) in production.
3434
#
35-
# It defaults to 1 because it's impossible to reliably detect how many
36-
# CPU cores are available. Make sure to set the `WEB_CONCURRENCY` environment
37-
# variable to match the number of processors.
38-
workers_count = Integer(ENV.fetch("WEB_CONCURRENCY", 1))
35+
# Automatically detect the number of available processors in production.
36+
require "concurrent-ruby"
37+
workers_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.available_processor_count })
3938
workers workers_count if workers_count > 1
4039

4140
preload_app!

0 commit comments

Comments
 (0)