Class: Puma::DSL
Overview
The methods that are available for use inside the configuration file. These same methods are used in Puma cli and the rack handler internally.
Used manually (via CLI class):
config = Configuration.new({}) do |user_config|
user_config.port 3001
end
config.load
puts config.[:binds]
"tcp://127.0.0.1:3001"
Used to load file:
$ cat puma_config.rb
port 3002
config = Configuration.new(config_file: "puma_config.rb")
config.load
puts config.[:binds]
# => "tcp://127.0.0.1:3002"
You can also find many examples being used by the test suite in test/config.
Constant Summary
Constants included from ConfigDefault
ConfigDefault::DefaultRackup, ConfigDefault::DefaultTCPHost, ConfigDefault::DefaultTCPPort, ConfigDefault::DefaultWorkerShutdownTimeout, ConfigDefault::DefaultWorkerTimeout
Instance Method Summary collapse
- #_load_from(path) ⇒ Object
- #_offer_plugins ⇒ Object
-
#activate_control_app(url = "auto", opts = {}) ⇒ Object
Start the Puma control rack application on
url. -
#after_worker_fork(&block) ⇒ Object
(also: #after_worker_boot)
Code to run in the master after a worker has been started.
-
#app(obj = nil, &block) ⇒ Object
Use an object or block as the rack application.
-
#before_fork(&block) ⇒ Object
Code to run immediately before master process forks workers (once on boot).
-
#bind(url) ⇒ Object
Bind the server to
url. -
#clean_thread_locals(which = true) ⇒ Object
Work around leaky apps that leave garbage in Thread locals across requests.
- #clear_binds! ⇒ Object
-
#daemonize(which = true) ⇒ Object
Daemonize the server into the background.
-
#debug ⇒ Object
Show debugging info.
- #default_host ⇒ Object
-
#directory(dir) ⇒ Object
The directory to operate out of.
-
#drain_on_shutdown(which = true) ⇒ Object
When shutting down, drain the accept socket of pending connections and process them.
- #early_hints(answer = true) ⇒ Object
-
#environment(environment) ⇒ Object
Set the environment in which the rack’s app will run.
-
#extra_runtime_dependencies(answer = []) ⇒ Object
When using prune_bundler, if extra runtime dependencies need to be loaded to initialize your app, then this setting can be used.
-
#first_data_timeout(seconds) ⇒ Object
Define how long the tcp socket stays open, if no data has been received.
-
#force_shutdown_after(val = :forever) ⇒ Object
How long to wait for threads to stop when shutting them down.
- #get(key, default = nil) ⇒ Object
-
#initialize(options, config) ⇒ DSL
constructor
A new instance of DSL.
- #inject(&blk) ⇒ Object
-
#load(file) ⇒ Object
Load additional configuration from a file Files get loaded later via Configuration#load.
- #log_formatter(&block) ⇒ Object
-
#log_requests(which = true) ⇒ Object
Enable request logging.
-
#lowlevel_error_handler(obj = nil, &block) ⇒ Object
Use
objorblockas the low level error handler. -
#on_restart(&block) ⇒ Object
Code to run before doing a restart.
-
#on_worker_boot(&block) ⇒ Object
Code to run in a worker when it boots to setup the process before booting the app.
-
#on_worker_fork(&block) ⇒ Object
Code to run in the master right before a worker is started.
-
#on_worker_shutdown(&block) ⇒ Object
Code to run immediately before a worker shuts down (after it has finished processing HTTP requests).
-
#out_of_band(&block) ⇒ Object
Code to run out-of-band when the worker is idle.
-
#persistent_timeout(seconds) ⇒ Object
Define how long persistent connections can be idle before Puma closes them.
-
#pidfile(path) ⇒ Object
Store the pid of the server in the file at “path”.
-
#plugin(name) ⇒ Object
Load the named plugin for use by this configuration.
-
#port(port, host = nil) ⇒ Object
Define the TCP port to bind to.
-
#preload_app!(answer = true) ⇒ Object
Preload the application before starting the workers; this conflicts with phased restart feature.
-
#prune_bundler(answer = true) ⇒ Object
This option is used to allow your app and its gems to be properly reloaded when not using preload.
-
#queue_requests(answer = true) ⇒ Object
When set to true (the default), workers accept all requests and queue them before passing them to the handlers.
-
#quiet(which = true) ⇒ Object
Disable request logging, if this isn’t used it’ll be enabled by default.
-
#rackup(path) ⇒ Object
Load
pathas a rackup file. -
#raise_exception_on_sigterm(answer = true) ⇒ Object
By default, Puma will raise SignalException when SIGTERM is received.
-
#restart_command(cmd) ⇒ Object
Command to use to restart Puma.
- #set_default_host(host) ⇒ Object
-
#set_remote_address(val = :socket) ⇒ Object
Control how the remote address of the connection is set.
-
#shutdown_debug(val = true) ⇒ Object
When a shutdown is requested, the backtraces of all the threads will be written to $stdout.
-
#ssl_bind(host, port, opts) ⇒ Object
Instead of “bind ‘ssl://127.0.0.1:9292?key=key_path&cert=cert_path’” you can also use the “ssl_bind” option.
-
#state_path(path) ⇒ Object
Use
pathas the file to store the server info state. -
#stdout_redirect(stdout = nil, stderr = nil, append = false) ⇒ Object
Redirect STDOUT and STDERR to files specified.
-
#tag(string) ⇒ Object
Additional text to display in process listing.
-
#tcp_mode ⇒ Object
Run the app as a raw TCP app instead of an HTTP rack app.
-
#tcp_mode! ⇒ Object
Run Puma in TCP mode.
-
#threads(min, max) ⇒ Object
Configure
minto be the minimum number of threads to use to answer requests andmaxthe maximum. -
#worker_boot_timeout(timeout) ⇒ Object
Change the default worker timeout for booting.
-
#worker_directory(dir) ⇒ Object
DEPRECATED: The directory to operate out of.
-
#worker_shutdown_timeout(timeout) ⇒ Object
Set the timeout for worker shutdown.
-
#worker_timeout(timeout) ⇒ Object
Verifies that all workers have checked in to the master process within the given timeout.
-
#workers(count) ⇒ Object
How many worker processes to run.
Constructor Details
#initialize(options, config) ⇒ DSL
Returns a new instance of DSL.
36 37 38 39 40 41 |
# File 'lib/puma/dsl.rb', line 36 def initialize(, config) @config = config = @plugins = [] end |
Instance Method Details
#_load_from(path) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/puma/dsl.rb', line 43 def _load_from(path) if path @path = path instance_eval(File.read(path), path, 1) end ensure _offer_plugins end |
#_offer_plugins ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puma/dsl.rb', line 52 def _offer_plugins @plugins.each do |o| if o.respond_to? :config .shift o.config self end end @plugins.clear end |
#activate_control_app(url = "auto", opts = {}) ⇒ Object
Start the Puma control rack application on url. This application can be communicated with to control the main server. Additionally, you can provide an authentication token, so all requests to the control server will need to include that token as a query parameter. This allows for simple authentication.
Check out App::Status to see what the app has available.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/puma/dsl.rb', line 123 def activate_control_app(url="auto", opts={}) if url == "auto" path = Configuration.temp_path [:control_url] = "unix://#{path}" [:control_url_temp] = path else [:control_url] = url end if opts[:no_token] # We need to use 'none' rather than :none because this value will be # passed on to an instance of OptionParser, which doesn't support # symbols as option values. # # See: https://github.com/puma/puma/issues/1193#issuecomment-305995488 auth_token = 'none' else auth_token = opts[:auth_token] auth_token ||= Configuration.random_token end [:control_auth_token] = auth_token [:control_url_umask] = opts[:umask] if opts[:umask] end |
#after_worker_fork(&block) ⇒ Object Also known as: after_worker_boot
Cluster mode only.
Code to run in the master after a worker has been started. The worker’s index is passed as an argument.
This is called everytime a worker is to be started.
508 509 510 511 |
# File 'lib/puma/dsl.rb', line 508 def after_worker_fork(&block) [:after_worker_fork] ||= [] [:after_worker_fork] = block end |
#app(obj = nil, &block) ⇒ Object
Use an object or block as the rack application. This allows the configuration file to be the application itself.
101 102 103 104 105 106 107 |
# File 'lib/puma/dsl.rb', line 101 def app(obj=nil, &block) obj ||= block raise "Provide either a #call'able or a block" unless obj [:app] = obj end |
#before_fork(&block) ⇒ Object
Cluster mode only.
Code to run immediately before master process forks workers (once on boot). These hooks can block if necessary to wait for background operations unknown to Puma to finish before the process terminates. This can be used to close any connections to remote servers (database, Redis, …) that were opened when preloading the code.
This can be called multiple times to add several hooks.
446 447 448 449 |
# File 'lib/puma/dsl.rb', line 446 def before_fork(&block) [:before_fork] ||= [] [:before_fork] << block end |
#bind(url) ⇒ Object
Bind the server to url. “tcp://”, “unix://” and “ssl://” are the only accepted protocols. Multiple urls can be bound to, calling ‘bind` does not overwrite previous bindings.
The default is “tcp://0.0.0.0:9292”.
You can use query parameters within the url to specify options:
- Set the socket backlog depth with +backlog+, default is 1024.
- Set up an SSL certificate with +key+ & +cert+.
- Set whether to optimize for low latency instead of throughput with
+low_latency+, default is to optimize for low latency. This is done
via +Socket::TCP_NODELAY+.
- Set socket with +umask+.
178 179 180 181 |
# File 'lib/puma/dsl.rb', line 178 def bind(url) [:binds] ||= [] [:binds] << url end |
#clean_thread_locals(which = true) ⇒ Object
Work around leaky apps that leave garbage in Thread locals across requests.
209 210 211 |
# File 'lib/puma/dsl.rb', line 209 def clean_thread_locals(which=true) [:clean_thread_locals] = which end |
#clear_binds! ⇒ Object
183 184 185 |
# File 'lib/puma/dsl.rb', line 183 def clear_binds! [:binds] = [] end |
#daemonize(which = true) ⇒ Object
Daemonize the server into the background. It’s highly recommended to use this in combination with pidfile and stdout_redirect.
The default is “false”.
223 224 225 |
# File 'lib/puma/dsl.rb', line 223 def daemonize(which=true) [:daemon] = which end |
#debug ⇒ Object
Show debugging info
314 315 316 |
# File 'lib/puma/dsl.rb', line 314 def debug [:debug] = true end |
#default_host ⇒ Object
67 68 69 |
# File 'lib/puma/dsl.rb', line 67 def default_host [:default_host] || Configuration::DefaultTCPHost end |
#directory(dir) ⇒ Object
The directory to operate out of.
The default is the current directory.
535 536 537 |
# File 'lib/puma/dsl.rb', line 535 def directory(dir) [:directory] = dir.to_s end |
#drain_on_shutdown(which = true) ⇒ Object
When shutting down, drain the accept socket of pending connections and process them. This loops over the accept socket until there are no more read events and then stops looking and waits for the requests to finish.
231 232 233 |
# File 'lib/puma/dsl.rb', line 231 def drain_on_shutdown(which=true) [:drain_on_shutdown] = which end |
#early_hints(answer = true) ⇒ Object
334 335 336 |
# File 'lib/puma/dsl.rb', line 334 def early_hints(answer=true) [:early_hints] = answer end |
#environment(environment) ⇒ Object
Set the environment in which the rack’s app will run. The value must be a string.
The default is “development”.
242 243 244 |
# File 'lib/puma/dsl.rb', line 242 def environment(environment) [:environment] = environment end |
#extra_runtime_dependencies(answer = []) ⇒ Object
When using prune_bundler, if extra runtime dependencies need to be loaded to initialize your app, then this setting can be used. This includes any Puma plugins.
Before bundler is pruned, the gem names supplied will be looked up in the bundler context and then loaded again after bundler is pruned. Only applies if prune_bundler is used.
618 619 620 |
# File 'lib/puma/dsl.rb', line 618 def extra_runtime_dependencies(answer = []) [:extra_runtime_dependencies] = Array(answer) end |
#first_data_timeout(seconds) ⇒ Object
Define how long the tcp socket stays open, if no data has been received.
203 204 205 |
# File 'lib/puma/dsl.rb', line 203 def first_data_timeout(seconds) [:first_data_timeout] = Integer(seconds) end |
#force_shutdown_after(val = :forever) ⇒ Object
How long to wait for threads to stop when shutting them down. Defaults to :forever. Specifying :immediately will cause Puma to kill the threads immediately. Otherwise the value is the number of seconds to wait.
Puma always waits a few seconds after killing a thread for it to try to finish up it’s work, even in :immediately mode.
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/puma/dsl.rb', line 253 def force_shutdown_after(val=:forever) i = case val when :forever -1 when :immediately 0 else Integer(val) end [:force_shutdown_after] = i end |
#get(key, default = nil) ⇒ Object
75 76 77 |
# File 'lib/puma/dsl.rb', line 75 def get(key,default=nil) [key.to_sym] || default end |
#inject(&blk) ⇒ Object
71 72 73 |
# File 'lib/puma/dsl.rb', line 71 def inject(&blk) instance_eval(&blk) end |
#load(file) ⇒ Object
Load additional configuration from a file Files get loaded later via Configuration#load
150 151 152 153 |
# File 'lib/puma/dsl.rb', line 150 def load(file) [:config_files] ||= [] [:config_files] << file end |
#log_formatter(&block) ⇒ Object
351 352 353 |
# File 'lib/puma/dsl.rb', line 351 def log_formatter(&block) [:log_formatter] = block end |
#log_requests(which = true) ⇒ Object
Enable request logging
308 309 310 |
# File 'lib/puma/dsl.rb', line 308 def log_requests(which=true) [:log_requests] = which end |
#lowlevel_error_handler(obj = nil, &block) ⇒ Object
Use obj or block as the low level error handler. This allows the configuration file to change the default error on the server.
567 568 569 570 571 |
# File 'lib/puma/dsl.rb', line 567 def lowlevel_error_handler(obj=nil, &block) obj ||= block raise "Provide either a #call'able or a block" unless obj [:lowlevel_error_handler] = obj end |
#on_restart(&block) ⇒ Object
Code to run before doing a restart. This code should close log files, database connections, etc.
This can be called multiple times to add code each time.
275 276 277 278 |
# File 'lib/puma/dsl.rb', line 275 def on_restart(&block) [:on_restart] ||= [] [:on_restart] << block end |
#on_worker_boot(&block) ⇒ Object
Cluster mode only.
Code to run in a worker when it boots to setup the process before booting the app.
This can be called multiple times to add several hooks.
461 462 463 464 |
# File 'lib/puma/dsl.rb', line 461 def on_worker_boot(&block) [:before_worker_boot] ||= [] [:before_worker_boot] << block end |
#on_worker_fork(&block) ⇒ Object
Cluster mode only.
Code to run in the master right before a worker is started. The worker’s index is passed as an argument.
This can be called multiple times to add several hooks.
493 494 495 496 |
# File 'lib/puma/dsl.rb', line 493 def on_worker_fork(&block) [:before_worker_fork] ||= [] [:before_worker_fork] << block end |
#on_worker_shutdown(&block) ⇒ Object
Cluster mode only.
Code to run immediately before a worker shuts down (after it has finished processing HTTP requests). These hooks can block if necessary to wait for background operations unknown to Puma to finish before the process terminates.
This can be called multiple times to add several hooks.
478 479 480 481 |
# File 'lib/puma/dsl.rb', line 478 def on_worker_shutdown(&block) [:before_worker_shutdown] ||= [] [:before_worker_shutdown] << block end |
#out_of_band(&block) ⇒ Object
Code to run out-of-band when the worker is idle. These hooks run immediately after a request has finished processing and there are no busy threads on the worker. The worker doesn’t accept new requests until this code finishes.
This hook is useful for running out-of-band garbage collection or scheduling asynchronous tasks to execute after a response.
This can be called multiple times to add several hooks.
524 525 526 527 |
# File 'lib/puma/dsl.rb', line 524 def out_of_band(&block) [:out_of_band] ||= [] [:out_of_band] << block end |
#persistent_timeout(seconds) ⇒ Object
Define how long persistent connections can be idle before Puma closes them.
198 199 200 |
# File 'lib/puma/dsl.rb', line 198 def persistent_timeout(seconds) [:persistent_timeout] = Integer(seconds) end |
#pidfile(path) ⇒ Object
Store the pid of the server in the file at “path”.
294 295 296 |
# File 'lib/puma/dsl.rb', line 294 def pidfile(path) [:pidfile] = path.to_s end |
#plugin(name) ⇒ Object
Load the named plugin for use by this configuration
81 82 83 |
# File 'lib/puma/dsl.rb', line 81 def plugin(name) @plugins << @config.load_plugin(name) end |
#port(port, host = nil) ⇒ Object
Define the TCP port to bind to. Use bind for more advanced options.
191 192 193 194 |
# File 'lib/puma/dsl.rb', line 191 def port(port, host=nil) host ||= default_host bind "tcp://#{host}:#{port}" end |
#preload_app!(answer = true) ⇒ Object
Cluster mode only.
Preload the application before starting the workers; this conflicts with phased restart feature. This is off by default.
556 557 558 |
# File 'lib/puma/dsl.rb', line 556 def preload_app!(answer=true) [:preload_app] = answer end |
#prune_bundler(answer = true) ⇒ Object
This is incompatible with preload_app!.
This is only supported for RubyGems 2.2+
This option is used to allow your app and its gems to be properly reloaded when not using preload.
When set, if Puma detects that it’s been invoked in the context of Bundler, it will cleanup the environment and re-run itself outside the Bundler environment, but directly using the files that Bundler has setup.
This means that Puma is now decoupled from your Bundler context and when each worker loads, it will be loading a new Bundler context and thus can float around as the release dictates.
See also: extra_runtime_dependencies
590 591 592 |
# File 'lib/puma/dsl.rb', line 590 def prune_bundler(answer=true) [:prune_bundler] = answer end |
#queue_requests(answer = true) ⇒ Object
When set to true (the default), workers accept all requests and queue them before passing them to the handlers. When set to false, each worker process accepts exactly as many requests as it is configured to simultaneously handle.
Queueing requests generally improves performance. In some cases, such as a single threaded application, it may be better to ensure requests get balanced across workers.
Note that setting this to false disables HTTP keepalive and slow clients will occupy a handler thread while the request is being sent. A reverse proxy, such as nginx, can handle slow clients and queue requests before they reach Puma.
687 688 689 |
# File 'lib/puma/dsl.rb', line 687 def queue_requests(answer=true) [:queue_requests] = answer end |
#quiet(which = true) ⇒ Object
Disable request logging, if this isn’t used it’ll be enabled by default.
302 303 304 |
# File 'lib/puma/dsl.rb', line 302 def quiet(which=true) [:log_requests] = !which end |
#rackup(path) ⇒ Object
Load path as a rackup file.
The default is “config.ru”.
324 325 326 |
# File 'lib/puma/dsl.rb', line 324 def rackup(path) [:rackup] = path.to_s end |
#raise_exception_on_sigterm(answer = true) ⇒ Object
By default, Puma will raise SignalException when SIGTERM is received. In environments where SIGTERM is something expected, you can suppress these with this option.
This can be useful for example in Kubernetes, where rolling restart is guaranteed usually on infrastructure level.
603 604 605 |
# File 'lib/puma/dsl.rb', line 603 def raise_exception_on_sigterm(answer=true) [:raise_exception_on_sigterm] = answer end |
#restart_command(cmd) ⇒ Object
Command to use to restart Puma. This should be just how to load Puma itself (ie. ‘ruby -Ilib bin/puma’), not the arguments to Puma, as those are the same as the original process.
286 287 288 |
# File 'lib/puma/dsl.rb', line 286 def restart_command(cmd) [:restart_cmd] = cmd.to_s end |
#set_default_host(host) ⇒ Object
63 64 65 |
# File 'lib/puma/dsl.rb', line 63 def set_default_host(host) [:default_host] = host end |
#set_remote_address(val = :socket) ⇒ Object
Control how the remote address of the connection is set. This is configurable because to calculate the true socket peer address a kernel syscall is required which for very fast rack handlers slows down the handling significantly.
There are 4 possible values:
-
:socket (the default) - read the peername from the socket using the
syscall. This is the normal behavior. -
:localhost - set the remote address to “127.0.0.1”
-
header: http_header - set the remote address to the value of the
provided http header. For instance: `set_remote_address header: "X-Real-IP"`. Only the first word (as separated by spaces or comma) is used, allowing headers such as X-Forwarded-For to be used as well. -
Any string - this allows you to hardcode remote address to any value
you wish. Because Puma never uses this field anyway, it's format is entirely in your hands.
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/puma/dsl.rb', line 717 def set_remote_address(val=:socket) case val when :socket [:remote_address] = val when :localhost [:remote_address] = :value [:remote_address_value] = "127.0.0.1".freeze when String [:remote_address] = :value [:remote_address_value] = val when Hash if hdr = val[:header] [:remote_address] = :header [:remote_address_header] = "HTTP_" + hdr.upcase.tr("-", "_") else raise "Invalid value for set_remote_address - #{val.inspect}" end else raise "Invalid value for set_remote_address - #{val}" end end |
#shutdown_debug(val = true) ⇒ Object
When a shutdown is requested, the backtraces of all the threads will be written to $stdout. This can help figure out why shutdown is hanging.
694 695 696 |
# File 'lib/puma/dsl.rb', line 694 def shutdown_debug(val=true) [:shutdown_debug] = val end |
#ssl_bind(host, port, opts) ⇒ Object
Instead of “bind ‘ssl://127.0.0.1:9292?key=key_path&cert=cert_path’” you can also use the “ssl_bind” option.
398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/puma/dsl.rb', line 398 def ssl_bind(host, port, opts) verify = opts.fetch(:verify_mode, 'none').to_s no_tlsv1 = opts.fetch(:no_tlsv1, 'false') no_tlsv1_1 = opts.fetch(:no_tlsv1_1, 'false') ca_additions = "&ca=#{opts[:ca]}" if ['peer', 'force_peer'].include?(verify) if defined?(JRUBY_VERSION) keystore_additions = "keystore=#{opts[:keystore]}&keystore-pass=#{opts[:keystore_pass]}" bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}&#{keystore_additions}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}&no_tlsv1_1=#{no_tlsv1_1}#{ca_additions}" else ssl_cipher_filter = "&ssl_cipher_filter=#{opts[:ssl_cipher_filter]}" if opts[:ssl_cipher_filter] bind "ssl://#{host}:#{port}?cert=#{opts[:cert]}&key=#{opts[:key]}#{ssl_cipher_filter}&verify_mode=#{verify}&no_tlsv1=#{no_tlsv1}&no_tlsv1_1=#{no_tlsv1_1}#{ca_additions}" end end |
#state_path(path) ⇒ Object
Use path as the file to store the server info state. This is used by pumactl to query and control the server.
418 419 420 |
# File 'lib/puma/dsl.rb', line 418 def state_path(path) [:state] = path.to_s end |
#stdout_redirect(stdout = nil, stderr = nil, append = false) ⇒ Object
Redirect STDOUT and STDERR to files specified. The append parameter specifies whether the output is appended, the default is false.
345 346 347 348 349 |
# File 'lib/puma/dsl.rb', line 345 def stdout_redirect(stdout=nil, stderr=nil, append=false) [:redirect_stdout] = stdout [:redirect_stderr] = stderr [:redirect_append] = append end |
#tag(string) ⇒ Object
Additional text to display in process listing.
If you do not specify a tag, Puma will infer it. If you do not want Puma to add a tag, use an empty string.
631 632 633 |
# File 'lib/puma/dsl.rb', line 631 def tag(string) [:tag] = string.to_s end |
#tcp_mode ⇒ Object
Run the app as a raw TCP app instead of an HTTP rack app.
546 547 548 |
# File 'lib/puma/dsl.rb', line 546 def tcp_mode [:mode] = :tcp end |
#tcp_mode! ⇒ Object
Run Puma in TCP mode
330 331 332 |
# File 'lib/puma/dsl.rb', line 330 def tcp_mode! [:mode] = :tcp end |
#threads(min, max) ⇒ Object
Configure min to be the minimum number of threads to use to answer requests and max the maximum.
The default is “0, 16”.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/puma/dsl.rb', line 364 def threads(min, max) min = Integer(min) max = Integer(max) if min > max raise "The minimum (#{min}) number of threads must be less than or equal to the max (#{max})" end if max < 1 raise "The maximum number of threads (#{max}) must be greater than 0" end [:min_threads] = min [:max_threads] = max end |
#worker_boot_timeout(timeout) ⇒ Object
Cluster mode only.
Change the default worker timeout for booting.
If unspecified, this defaults to the value of worker_timeout.
@example:
worker_boot_timeout 60
663 664 665 |
# File 'lib/puma/dsl.rb', line 663 def worker_boot_timeout(timeout) [:worker_boot_timeout] = Integer(timeout) end |
#worker_directory(dir) ⇒ Object
DEPRECATED: The directory to operate out of.
540 541 542 543 |
# File 'lib/puma/dsl.rb', line 540 def worker_directory(dir) $stderr.puts "worker_directory is deprecated. Please use `directory`" directory dir end |
#worker_shutdown_timeout(timeout) ⇒ Object
Cluster mode only.
Set the timeout for worker shutdown
670 671 672 |
# File 'lib/puma/dsl.rb', line 670 def worker_shutdown_timeout(timeout) [:worker_shutdown_timeout] = Integer(timeout) end |
#worker_timeout(timeout) ⇒ Object
Cluster mode only.
Verifies that all workers have checked in to the master process within the given timeout. If not the worker process will be restarted. This is not a request timeout, it is to protect against a hung or dead process. Setting this value will not protect against slow requests.
The minimum value is 6 seconds, the default value is 60 seconds.
645 646 647 648 649 650 651 652 653 654 |
# File 'lib/puma/dsl.rb', line 645 def worker_timeout(timeout) timeout = Integer(timeout) min = Const::WORKER_CHECK_INTERVAL if timeout <= min raise "The minimum worker_timeout must be greater than the worker reporting interval (#{min})" end [:worker_timeout] = timeout end |
#workers(count) ⇒ Object
Cluster mode only.
How many worker processes to run. Typically this is set to to the number of available cores.
The default is 0.
428 429 430 |
# File 'lib/puma/dsl.rb', line 428 def workers(count) [:workers] = count.to_i end |