From a01419c9c1afe2a824d462d342d109ff0b1966b8 Mon Sep 17 00:00:00 2001 From: Alejandro Martinez Ruiz Date: Fri, 6 Nov 2015 17:46:48 +0100 Subject: [PATCH] cluster: add worker_boot_timeout option When your workers are loading, the normal operation timeout is in effect. If you spawn many workers or have them perform a lot of work or wait for just long enough before actually booting, they will be killed by the worker ping timeout. If you want to control the exact timeout for your workers to boot, specify the `worker_boot_timeout` option. Otherwise, it defaults to the value of the `worker_timeout` option. --- examples/config.rb | 6 ++++++ lib/puma/cluster.rb | 1 + lib/puma/configuration.rb | 1 + lib/puma/dsl.rb | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/examples/config.rb b/examples/config.rb index 19f2bbe6..f0749ed9 100644 --- a/examples/config.rb +++ b/examples/config.rb @@ -149,6 +149,12 @@ # # worker_timeout 60 +# Change the default worker timeout for booting +# +# If unspecified, this defaults to the value of worker_timeout. +# +# worker_boot_timeout 60 + # === Puma control rack application === # Start the puma control rack application on "url". This application can diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index c34845e7..fb2e76e0 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -136,6 +136,7 @@ module Puma any = false @workers.each do |w| + next if !w.booted? && !w.ping_timeout?(@options[:worker_boot_timeout]) if w.ping_timeout?(@options[:worker_timeout]) log "! Terminating timed out worker: #{w.pid}" w.kill diff --git a/lib/puma/configuration.rb b/lib/puma/configuration.rb index 80d42f00..475de7a8 100644 --- a/lib/puma/configuration.rb +++ b/lib/puma/configuration.rb @@ -27,6 +27,7 @@ module Puma @conf[:before_worker_fork] ||= [] @conf[:after_worker_boot] ||= [] @conf[:worker_timeout] ||= DefaultWorkerTimeout + @conf[:worker_boot_timeout] ||= @conf[:worker_timeout] @conf[:worker_shutdown_timeout] ||= DefaultWorkerShutdownTimeout @options = {} diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index e5c6fd31..c07b4409 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -261,6 +261,11 @@ module Puma @options[:worker_timeout] = timeout end + # *Cluster mode only* Set the timeout for workers to boot + def worker_boot_timeout(timeout) + @options[:worker_boot_timeout] = timeout + end + # *Cluster mode only* Set the timeout for worker shutdown def worker_shutdown_timeout(timeout) @options[:worker_shutdown_timeout] = timeout