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
add RAILS_MIN_THREADS, RAILS_MAX_THREADS, set default worker, preload… #2143
Changes from 12 commits
b606a33
d37ba21
70e2ae9
0593668
2ba0d6e
5a95dae
ebc1422
d8b72e8
e1a1750
d24455c
b257dfe
b2dad7b
e552e6c
3645f75
6200e52
c12340b
338099f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,12 @@ def initialize(user_options={}, default_options = {}, &block) | |
@file_dsl = DSL.new(@options.file_options, self) | ||
@default_dsl = DSL.new(@options.default_options, self) | ||
|
||
workers_supported = !(Puma.jruby? || Puma.windows?) | ||
|
||
if !@options[:prune_bundler] | ||
default_options[:preload_app] = (@options[:workers] > 1) && workers_supported | ||
end | ||
|
||
if block | ||
configure(&block) | ||
end | ||
|
@@ -167,14 +173,20 @@ def flatten! | |
self | ||
end | ||
|
||
def default_max_threads | ||
return 5 if Puma.mri? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer a ternary here instead of return. |
||
16 | ||
end | ||
|
||
def puma_default_options | ||
{ | ||
:min_threads => 0, | ||
:max_threads => 16, | ||
:min_threads => Integer(ENV['PUMA_MIN_THREADS'] || ENV['MIN_THREADS'] || 0), | ||
:max_threads => Integer(ENV['PUMA_MAX_THREADS'] || ENV['MAX_THREADS'] || default_max_threads), | ||
:log_requests => false, | ||
:debug => false, | ||
:binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"], | ||
:workers => 0, | ||
:workers => Integer(ENV['WEB_CONCURRENCY'] || 0), | ||
:daemon => false, | ||
jalevin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:mode => :http, | ||
:worker_timeout => DefaultWorkerTimeout, | ||
:worker_boot_timeout => DefaultWorkerTimeout, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,58 @@ | |
class TestConfigFile < TestConfigFileBase | ||
parallelize_me! | ||
|
||
def test_default_max_threads | ||
max_threads = 16 | ||
max_threads = 5 if RUBY_ENGINE.nil? || RUBY_ENGINE == 'ruby' | ||
assert_equal max_threads, Puma::Configuration.new.default_max_threads | ||
end | ||
|
||
def test_config_loads_correct_min_threads | ||
conf = Puma::Configuration.new | ||
assert_equal 0, conf.options.default_options[:min_threads] | ||
|
||
ENV['MIN_THREADS'] = '7' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting a global and running tests in parallel threads, you're gonna have a Bad Time (as you've seen on your tests). Maybe just removing parallelize_me will fix everything here. Put these tests into a separate test class which is not paralellized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scratch that- extrapolated into it's own class and used the with_env helper. All seems fine. |
||
conf = Puma::Configuration.new | ||
assert_equal 7, conf.options.default_options[:min_threads] | ||
|
||
ENV['PUMA_MIN_THREADS'] = '8' | ||
conf = Puma::Configuration.new | ||
assert_equal 8, conf.options.default_options[:min_threads] | ||
end | ||
|
||
def test_config_loads_correct_max_threads | ||
conf = Puma::Configuration.new | ||
assert_equal conf.default_max_threads, conf.options.default_options[:max_threads] | ||
|
||
ENV['MAX_THREADS'] = '7' | ||
conf = Puma::Configuration.new | ||
assert_equal 7, conf.options.default_options[:max_threads] | ||
|
||
ENV['PUMA_MAX_THREADS'] = '8' | ||
conf = Puma::Configuration.new | ||
assert_equal 8, conf.options.default_options[:max_threads] | ||
end | ||
|
||
def test_config_loads_correct_workers | ||
conf = Puma::Configuration.new | ||
assert_equal 0, conf.options.default_options[:workers] | ||
|
||
ENV['WEB_CONCURRENCY'] = '8' | ||
conf = Puma::Configuration.new | ||
assert_equal 8, conf.options.default_options[:workers] | ||
end | ||
|
||
def test_config_preloads_app_if_using_workers | ||
ENV['WEB_CONCURRENCY'] = '0' | ||
conf = Puma::Configuration.new | ||
assert_equal false, conf.options.default_options[:preload_app] | ||
|
||
ENV['WEB_CONCURRENCY'] = '2' | ||
preload = Puma::Plugin.new.workers_supported? | ||
conf = Puma::Configuration.new | ||
assert_equal preload, conf.options.default_options[:preload_app] | ||
end | ||
|
||
def test_app_from_rackup | ||
conf = Puma::Configuration.new do |c| | ||
c.rackup "test/rackup/hello-bind.ru" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
::Process.respond_to? :fork
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also no need to assign to a variable, just put it on line 143