From b606a33577a00868d98a8ffa369a181797686cdc Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 1 Mar 2020 16:12:36 -0900 Subject: [PATCH 01/14] add RAILS_MIN_THREADS, RAILS_MAX_THREADS, set default worker, preload if using workers --- lib/puma/configuration.rb | 20 ++++++++++--- test/test_config.rb | 60 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 838e61731a..d869d178a4 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -106,7 +106,7 @@ def finalize_values # # It also handles loading plugins. # - # > Note: `:port` and `:host` are not valid keys. By the time they make it to the + # > Note: `:port` and `:host` are not valid keys. By they time they make it to the # configuration options they are expected to be incorporated into a `:binds` key. # Under the hood the DSL maps `port` and `host` calls to `:binds` # @@ -137,6 +137,8 @@ def initialize(user_options={}, default_options = {}, &block) @file_dsl = DSL.new(@options.file_options, self) @default_dsl = DSL.new(@options.default_options, self) + default_options[:preload_app] = (default_options[:workers] > 1 && Puma::Plugin.new.workers_supported?) + if block configure(&block) end @@ -167,14 +169,24 @@ def flatten! self end + def default_workers + return 0 if Puma.jruby? || Puma.windows? + 1 + end + + def default_max_threads + return 5 if RUBY_ENGINE.nil? || RUBY_ENGINE == 'ruby' + 16 + end + def puma_default_options { - :min_threads => 0, - :max_threads => 16, + :min_threads => Integer(ENV['RAILS_MIN_THREADS'] || ENV['MIN_THREADS'] || 0), + :max_threads => Integer(ENV['RAILS_MAX_THREADS'] || ENV['MAX_THREADS'] || default_max_threads), :log_requests => false, :debug => false, :binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"], - :workers => 0, + :workers => Integer(ENV['WEB_CONCURRENCY'] || default_workers), :daemon => false, :mode => :http, :worker_timeout => DefaultWorkerTimeout, diff --git a/test/test_config.rb b/test/test_config.rb index d3d87d0902..8f05d1e57f 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -8,6 +8,64 @@ class TestConfigFile < TestConfigFileBase parallelize_me! + def test_default_workers + workers = 1 + workers = 0 if Puma.jruby? || Puma.windows? + assert_equal workers, Puma::Configuration.new.default_workers + end + + 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' + conf = Puma::Configuration.new + assert_equal 7, conf.options.default_options[:min_threads] + + ENV['RAILS_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['RAILS_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 conf.default_workers, 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" @@ -251,4 +309,4 @@ def test_config_files_with_specified_environment def teardown FileUtils.rm_r("config/puma") end -end +end \ No newline at end of file From d37ba211dd5385e3dd7cf503c87eaf50f94cf06c Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 1 Mar 2020 16:25:38 -0900 Subject: [PATCH 02/14] fix formatting. update history --- History.md | 6 ++++++ test/test_config.rb | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/History.md b/History.md index 25eab1b640..b9d6b80e26 100644 --- a/History.md +++ b/History.md @@ -10,6 +10,12 @@ * Changed #connected_port to #connected_ports (#2076) * `--control` has been removed. Use `--control-url` (#1487) * `worker_directory` has been removed. Use `directory` + * min_threads now set by environment variables RAILS_MIN_THREADS and MIN_THREADS + * max_threads now set by environment variables RAILS_MAX_THREADS and MAX_THREADS + * max_threads default to 5 in MRI or 16 for all other interpretters + * default to 1 worker if running on MRI or 0 if jruby/windows + * preload by default if workers > 1 and interpretter supports workers + * Bugfixes * Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069) diff --git a/test/test_config.rb b/test/test_config.rb index 8f05d1e57f..ad5d813a72 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -13,7 +13,7 @@ def test_default_workers workers = 0 if Puma.jruby? || Puma.windows? assert_equal workers, Puma::Configuration.new.default_workers end - + def test_default_max_threads max_threads = 16 max_threads = 5 if RUBY_ENGINE.nil? || RUBY_ENGINE == 'ruby' @@ -23,33 +23,33 @@ def test_default_max_threads def test_config_loads_correct_min_threads conf = Puma::Configuration.new assert_equal 0, conf.options.default_options[:min_threads] - + ENV['MIN_THREADS'] = '7' conf = Puma::Configuration.new assert_equal 7, conf.options.default_options[:min_threads] - - ENV['RAILS_MIN_THREADS'] = '8' + + ENV['RAILS_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['RAILS_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 conf.default_workers, conf.options.default_options[:workers] - + ENV['WEB_CONCURRENCY'] = '8' conf = Puma::Configuration.new assert_equal 8, conf.options.default_options[:workers] @@ -59,7 +59,7 @@ 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 @@ -309,4 +309,4 @@ def test_config_files_with_specified_environment def teardown FileUtils.rm_r("config/puma") end -end \ No newline at end of file +end From 70e2ae922f6d801c839e7af707d9cbcd74e9237d Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 1 Mar 2020 16:29:07 -0900 Subject: [PATCH 03/14] fix formatting --- lib/puma/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index d869d178a4..d6d1260cbb 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -173,7 +173,7 @@ def default_workers return 0 if Puma.jruby? || Puma.windows? 1 end - + def default_max_threads return 5 if RUBY_ENGINE.nil? || RUBY_ENGINE == 'ruby' 16 From 05936689c832e33a915a052b10a20b5bbd173e1a Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 1 Mar 2020 16:12:36 -0900 Subject: [PATCH 04/14] add RAILS_MIN_THREADS, RAILS_MAX_THREADS, set default worker, preload if using workers --- History.md | 5 ++++ lib/puma/configuration.rb | 13 +++++++--- lib/puma/detect.rb | 4 +++ test/test_config.rb | 52 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 25eab1b640..873229f6fb 100644 --- a/History.md +++ b/History.md @@ -10,6 +10,11 @@ * Changed #connected_port to #connected_ports (#2076) * `--control` has been removed. Use `--control-url` (#1487) * `worker_directory` has been removed. Use `directory` + * min_threads now set by environment variables RAILS_MIN_THREADS and MIN_THREADS + * max_threads now set by environment variables RAILS_MAX_THREADS and MAX_THREADS + * max_threads default to 5 in MRI or 16 for all other interpretters + * preload by default if workers > 1 and interpretter supports workers + * Bugfixes * Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 838e61731a..797f40a89f 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,6 +137,8 @@ def initialize(user_options={}, default_options = {}, &block) @file_dsl = DSL.new(@options.file_options, self) @default_dsl = DSL.new(@options.default_options, self) + default_options[:preload_app] = (default_options[:workers] > 1 && Puma::Plugin.new.workers_supported?) + if block configure(&block) end @@ -167,14 +169,19 @@ def flatten! self end + def default_max_threads + return 5 if Puma.mri? + 16 + end + def puma_default_options { - :min_threads => 0, - :max_threads => 16, + :min_threads => Integer(ENV['RAILS_MIN_THREADS'] || ENV['MIN_THREADS'] || 0), + :max_threads => Integer(ENV['RAILS_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, :mode => :http, :worker_timeout => DefaultWorkerTimeout, diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index 0c87a45cd6..3dc4c06d39 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -12,4 +12,8 @@ def self.jruby? def self.windows? IS_WINDOWS end + + def self.mri? + RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil? + end end diff --git a/test/test_config.rb b/test/test_config.rb index d3d87d0902..3e69d4e86f 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -8,6 +8,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' + conf = Puma::Configuration.new + assert_equal 7, conf.options.default_options[:min_threads] + + ENV['RAILS_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['RAILS_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" From 5a95daeb1c081f56b013a7696333c1ea740fc537 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Mon, 9 Mar 2020 00:47:03 -0800 Subject: [PATCH 05/14] fix typo --- lib/puma/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 21810d05c8..797f40a89f 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -106,7 +106,7 @@ def finalize_values # # It also handles loading plugins. # - # > Note: `:port` and `:host` are not valid keys. By they time they make it to the + # > Note: `:port` and `:host` are not valid keys. By the time they make it to the # configuration options they are expected to be incorporated into a `:binds` key. # Under the hood the DSL maps `port` and `host` calls to `:binds` # From ebc1422cb9b896b9cd932528c24c1b1b7963bf2b Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Mon, 9 Mar 2020 00:48:10 -0800 Subject: [PATCH 06/14] stupid whitespace --- lib/puma/detect.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index 3dc4c06d39..c6b8ed880a 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -14,6 +14,6 @@ def self.windows? end def self.mri? - RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil? + RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil? end end From d8b72e84f56d6864815bc60b888de3a88c841618 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 12 Apr 2020 22:37:02 -0800 Subject: [PATCH 07/14] Look to use if user is pruning bundler. update cli tests. --- History.md | 4 ++-- lib/puma/configuration.rb | 12 +++++++++--- test/test_cli.rb | 9 ++++++--- test/test_config.rb | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/History.md b/History.md index 873229f6fb..664a64b079 100644 --- a/History.md +++ b/History.md @@ -10,8 +10,8 @@ * Changed #connected_port to #connected_ports (#2076) * `--control` has been removed. Use `--control-url` (#1487) * `worker_directory` has been removed. Use `directory` - * min_threads now set by environment variables RAILS_MIN_THREADS and MIN_THREADS - * max_threads now set by environment variables RAILS_MAX_THREADS and MAX_THREADS + * min_threads now set by environment variables PUMA_MIN_THREADS and MIN_THREADS + * max_threads now set by environment variables PUMA_MAX_THREADS and MAX_THREADS * max_threads default to 5 in MRI or 16 for all other interpretters * preload by default if workers > 1 and interpretter supports workers diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 797f40a89f..b798a38730 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,7 +137,13 @@ def initialize(user_options={}, default_options = {}, &block) @file_dsl = DSL.new(@options.file_options, self) @default_dsl = DSL.new(@options.default_options, self) - default_options[:preload_app] = (default_options[:workers] > 1 && Puma::Plugin.new.workers_supported?) + # 1. workers_supported - #Puma::Plugin.new.workers_supported?) + workers_supported = !(Puma.jruby? || Puma.windows?) + + # 2. preload app + if !@options[:prune_bundler] + default_options[:preload_app] =(@options[:workers] > 1) && workers_supported + end if block configure(&block) @@ -176,8 +182,8 @@ def default_max_threads def puma_default_options { - :min_threads => Integer(ENV['RAILS_MIN_THREADS'] || ENV['MIN_THREADS'] || 0), - :max_threads => Integer(ENV['RAILS_MAX_THREADS'] || ENV['MAX_THREADS'] || default_max_threads), + :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}"], diff --git a/test/test_cli.rb b/test/test_cli.rb index 0cbcb4ac1f..91a3752b62 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -55,7 +55,8 @@ def test_control_for_tcp body = s.read s.close - assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":16,"max_threads":16,"requests_count":0}/, body.split(/\r?\n/).last) + dmt = Puma::Configuration.new.default_max_threads + assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split(/\r?\n/).last) ensure cli.launcher.stop @@ -87,7 +88,8 @@ def test_control_for_ssl body = http.request(req).body end - expected_stats = /{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":16,"max_threads":16,"requests_count":0}/ + dmt = Puma::Configuration.new.default_max_threads + expected_stats = /{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt}/ assert_match(expected_stats, body.split(/\r?\n/).last) assert_equal([:started_at, :backlog, :running, :pool_capacity, :max_threads, :requests_count], Puma.stats.keys) @@ -167,7 +169,8 @@ def test_control body = s.read s.close - assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":16,"max_threads":16,"requests_count":0}/, body.split("\r\n").last) + dmt = Puma::Configuration.new.default_max_threads + assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split("\r\n").last) ensure if UNIX_SKT_EXIST cli.launcher.stop diff --git a/test/test_config.rb b/test/test_config.rb index 3e69d4e86f..2ae13ab5e7 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -22,7 +22,7 @@ def test_config_loads_correct_min_threads conf = Puma::Configuration.new assert_equal 7, conf.options.default_options[:min_threads] - ENV['RAILS_MIN_THREADS'] = '8' + ENV['PUMA_MIN_THREADS'] = '8' conf = Puma::Configuration.new assert_equal 8, conf.options.default_options[:min_threads] end @@ -35,7 +35,7 @@ def test_config_loads_correct_max_threads conf = Puma::Configuration.new assert_equal 7, conf.options.default_options[:max_threads] - ENV['RAILS_MAX_THREADS'] = '8' + ENV['PUMA_MAX_THREADS'] = '8' conf = Puma::Configuration.new assert_equal 8, conf.options.default_options[:max_threads] end From d24455cc5972eb2c281e2474c8fdd249b57c25f3 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 12 Apr 2020 22:42:16 -0800 Subject: [PATCH 08/14] fix formatting --- lib/puma/configuration.rb | 12 ++++++------ test/test_cli.rb | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index b798a38730..9757014c57 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,13 +137,13 @@ def initialize(user_options={}, default_options = {}, &block) @file_dsl = DSL.new(@options.file_options, self) @default_dsl = DSL.new(@options.default_options, self) - # 1. workers_supported - #Puma::Plugin.new.workers_supported?) - workers_supported = !(Puma.jruby? || Puma.windows?) + # 1. workers_supported - #Puma::Plugin.new.workers_supported?) + workers_supported = !(Puma.jruby? || Puma.windows?) - # 2. preload app - if !@options[:prune_bundler] - default_options[:preload_app] =(@options[:workers] > 1) && workers_supported - end + # 2. preload app + if !@options[:prune_bundler] + default_options[:preload_app] =(@options[:workers] > 1) && workers_supported + end if block configure(&block) diff --git a/test/test_cli.rb b/test/test_cli.rb index 91a3752b62..5a4adf5e7f 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -55,7 +55,7 @@ def test_control_for_tcp body = s.read s.close - dmt = Puma::Configuration.new.default_max_threads + dmt = Puma::Configuration.new.default_max_threads assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split(/\r?\n/).last) ensure @@ -88,8 +88,8 @@ def test_control_for_ssl body = http.request(req).body end - dmt = Puma::Configuration.new.default_max_threads - expected_stats = /{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt}/ + dmt = Puma::Configuration.new.default_max_threads + expected_stats = /{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt}/ assert_match(expected_stats, body.split(/\r?\n/).last) assert_equal([:started_at, :backlog, :running, :pool_capacity, :max_threads, :requests_count], Puma.stats.keys) @@ -169,7 +169,7 @@ def test_control body = s.read s.close - dmt = Puma::Configuration.new.default_max_threads + dmt = Puma::Configuration.new.default_max_threads assert_match(/{"started_at":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z","backlog":0,"running":0,"pool_capacity":#{dmt},"max_threads":#{dmt},"requests_count":0}/, body.split("\r\n").last) ensure if UNIX_SKT_EXIST From b2dad7b9f77bd4823eb70ddef68d87b2a660915d Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Mon, 13 Apr 2020 11:50:45 -0800 Subject: [PATCH 09/14] remove comments, should be ready.. lets see if tests still fail --- lib/puma/configuration.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index bf74f451cd..30992efdf0 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,12 +137,10 @@ def initialize(user_options={}, default_options = {}, &block) @file_dsl = DSL.new(@options.file_options, self) @default_dsl = DSL.new(@options.default_options, self) - # 1. workers_supported - #Puma::Plugin.new.workers_supported?) workers_supported = !(Puma.jruby? || Puma.windows?) - # 2. preload app if !@options[:prune_bundler] - default_options[:preload_app] =(@options[:workers] > 1) && workers_supported + default_options[:preload_app] = (@options[:workers] > 1) && workers_supported end if block From e552e6ce65b36d9f559d93494f1431719d6fed05 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 19 Apr 2020 17:48:20 -0800 Subject: [PATCH 10/14] ITS THE FINAL COUNTDOWWNNNNN.....(yeah, Ill rebase) --- lib/puma/configuration.rb | 7 +-- test/test_config.rb | 105 ++++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 50 deletions(-) diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 30992efdf0..da88acb693 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -137,10 +137,9 @@ 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 + default_options[:preload_app] = (@options[:workers] > 1) && ::Process.respond_to?(:fork) end if block @@ -174,8 +173,7 @@ def flatten! end def default_max_threads - return 5 if Puma.mri? - 16 + Puma.mri? ? 5 : 16 end def puma_default_options @@ -186,7 +184,6 @@ def puma_default_options :debug => false, :binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"], :workers => Integer(ENV['WEB_CONCURRENCY'] || 0), - :daemon => false, :mode => :http, :worker_timeout => DefaultWorkerTimeout, :worker_boot_timeout => DefaultWorkerTimeout, diff --git a/test/test_config.rb b/test/test_config.rb index 8de59b059b..b78a65f7d0 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -6,6 +6,7 @@ require "puma/configuration" require 'puma/events' + class TestConfigFile < TestConfigFileBase parallelize_me! @@ -15,51 +16,6 @@ def test_default_max_threads 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' - 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| @@ -327,6 +283,65 @@ def test_double_bind_port end end +class TestConfigEnvVariables < TestConfigFileBase + def test_config_loads_correct_min_threads + conf = Puma::Configuration.new + assert_equal 0, conf.options.default_options[:min_threads] + + with_env("MIN_THREADS" => "7") do + conf = Puma::Configuration.new + assert_equal 7, conf.options.default_options[:min_threads] + end + + with_env("PUMA_MIN_THREADS" => "8") do + conf = Puma::Configuration.new + assert_equal 8, conf.options.default_options[:min_threads] + end + end + + def test_config_loads_correct_max_threads + conf = Puma::Configuration.new + assert_equal conf.default_max_threads, conf.options.default_options[:max_threads] + + with_env("MAX_THREADS" => "7") do + conf = Puma::Configuration.new + assert_equal 7, conf.options.default_options[:max_threads] + end + + with_env("MAX_THREADS" => "8") do + conf = Puma::Configuration.new + assert_equal 8, conf.options.default_options[:max_threads] + end + end + + def test_config_does_not_load_workers_by_default + conf = Puma::Configuration.new + assert_equal 0, conf.options.default_options[:workers] + end + + def test_config_loads_workers_from_env + with_env("WEB_CONCURRENCY" => "9") do + conf = Puma::Configuration.new + assert_equal 9, conf.options.default_options[:workers] + end + end + + def test_config_does_not_preload_app_if_using_workers + with_env("WEB_CONCURRENCY" => "0") do + conf = Puma::Configuration.new + assert_equal false, conf.options.default_options[:preload_app] + end + end + + def test_config_preloads_app_if_using_workers + with_env("WEB_CONCURRENCY" => "2") do + preload = Puma::Plugin.new.workers_supported? + conf = Puma::Configuration.new + assert_equal preload, conf.options.default_options[:preload_app] + end + end +end + class TestConfigFileWithFakeEnv < TestConfigFileBase def setup FileUtils.mkpath("config/puma") From 3645f75bfc8f1d7bb1762b8627647673aacd4115 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 19 Apr 2020 22:22:44 -0800 Subject: [PATCH 11/14] fix typo in test --- test/test_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_config.rb b/test/test_config.rb index b78a65f7d0..dcc014737f 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -308,7 +308,7 @@ def test_config_loads_correct_max_threads assert_equal 7, conf.options.default_options[:max_threads] end - with_env("MAX_THREADS" => "8") do + with_env("PUMA_MAX_THREADS" => "8") do conf = Puma::Configuration.new assert_equal 8, conf.options.default_options[:max_threads] end From 6200e522448c5c5a4994a0644e2c1450ae297b6f Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 19 Apr 2020 22:38:46 -0800 Subject: [PATCH 12/14] tweak for truffleruby --- test/test_config.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_config.rb b/test/test_config.rb index dcc014737f..a76c1d0b77 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -335,9 +335,8 @@ def test_config_does_not_preload_app_if_using_workers def test_config_preloads_app_if_using_workers with_env("WEB_CONCURRENCY" => "2") do - preload = Puma::Plugin.new.workers_supported? conf = Puma::Configuration.new - assert_equal preload, conf.options.default_options[:preload_app] + assert_equal preload, conf.options.default_options[:preload_app] if ::Process.respond_to?(:fork) end end end From c12340b105799d1b78e4b05efc7467513639bff1 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 19 Apr 2020 23:03:39 -0800 Subject: [PATCH 13/14] add methods to detect truffle. exclude truffle from allowing workers --- lib/puma/detect.rb | 6 ++++++ lib/puma/plugin.rb | 2 +- test/test_config.rb | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index c6b8ed880a..d5f34c7c51 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -13,6 +13,12 @@ def self.windows? IS_WINDOWS end + IS_TRUFFLE = RUBY_PLATFORM == 'truffleruby' + + def self.truffle? + IS_TRUFFLE + end + def self.mri? RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil? end diff --git a/lib/puma/plugin.rb b/lib/puma/plugin.rb index 7c60be97de..3ae147e27a 100644 --- a/lib/puma/plugin.rb +++ b/lib/puma/plugin.rb @@ -109,7 +109,7 @@ def in_background(&blk) end def workers_supported? - return false if Puma.jruby? || Puma.windows? + return false if Puma.jruby? || Puma.windows? || Puma.truffle? true end end diff --git a/test/test_config.rb b/test/test_config.rb index a76c1d0b77..dcc014737f 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -335,8 +335,9 @@ def test_config_does_not_preload_app_if_using_workers def test_config_preloads_app_if_using_workers with_env("WEB_CONCURRENCY" => "2") do + preload = Puma::Plugin.new.workers_supported? conf = Puma::Configuration.new - assert_equal preload, conf.options.default_options[:preload_app] if ::Process.respond_to?(:fork) + assert_equal preload, conf.options.default_options[:preload_app] end end end From 338099fddafea76b4aeb068ca2dd546b4ca02f44 Mon Sep 17 00:00:00 2001 From: Jeff Levin Date: Sun, 19 Apr 2020 23:16:04 -0800 Subject: [PATCH 14/14] fix test for truffle ruby --- lib/puma/detect.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index d5f34c7c51..b4d3418060 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -13,7 +13,7 @@ def self.windows? IS_WINDOWS end - IS_TRUFFLE = RUBY_PLATFORM == 'truffleruby' + IS_TRUFFLE = RUBY_ENGINE == 'truffleruby' def self.truffle? IS_TRUFFLE