mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
add RAILS_MIN_THREADS, RAILS_MAX_THREADS, set default worker, preload if using workers
This commit is contained in:
parent
8f282206dc
commit
05936689c8
4 changed files with 71 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -137,6 +137,8 @@ module Puma
|
|||
@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 @@ module Puma
|
|||
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,
|
||||
|
|
|
@ -12,4 +12,8 @@ module Puma
|
|||
def self.windows?
|
||||
IS_WINDOWS
|
||||
end
|
||||
|
||||
def self.mri?
|
||||
RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,58 @@ require "puma/configuration"
|
|||
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"
|
||||
|
|
Loading…
Add table
Reference in a new issue