From 3fdf0c968153afc696a1cb237c1bec68e9d0eb5e Mon Sep 17 00:00:00 2001 From: Ben Osheroff Date: Thu, 14 Jan 2016 17:01:35 -0800 Subject: [PATCH] make phased restarts faster Have the worker send the master "tPID" immediately before shutdown; this lets the master move on to booting the next worker immediately, instead of waiting for the next iteration of the select() loop. --- lib/puma/cluster.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index d06a4d26..82a124a5 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -65,6 +65,14 @@ module Puma @stage = :booted end + def dead? + @dead + end + + def dead! + @dead = true + end + def ping! @last_checkin = Time.now end @@ -128,7 +136,7 @@ module Puma @workers.count { |w| !w.booted? } == 0 end - def check_workers(force=false) + def check_workers(force) return if !force && @next_check && @next_check >= Time.now @next_check = Time.now + 5 @@ -155,6 +163,8 @@ module Puma @workers.delete_if { |w| w.pid == pid } end + @workers.delete_if(&:dead?) + spawn_workers if all_workers_booted? @@ -242,6 +252,7 @@ module Puma hooks = @options[:before_worker_shutdown] hooks.each { |h| h.call(index) } ensure + @worker_write << "t#{Process.pid}\n" rescue nil @worker_write.close end @@ -412,6 +423,9 @@ module Puma w.boot! log "- Worker #{w.index} (pid: #{pid}) booted, phase: #{w.phase}" force_check = true + when "t" + w.dead! + force_check = true when "p" w.ping! end