From e9da4ce4c8917934242037db0c2735bd7dab1586 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Aug 2011 17:39:53 -0700 Subject: fix sleep/timeout activation accuracy I've noticed in stderr logs from some folks that (last resort) timeouts from the master process are taking too long to activate due to the workarounds for suspend/hibernation. --- lib/unicorn/http_server.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 4f516c9..1d51001 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -264,8 +264,8 @@ class Unicorn::HttpServer if (last_check + @timeout) >= (last_check = Time.now) sleep_time = murder_lazy_workers else - # wait for workers to wakeup on suspend sleep_time = @timeout/2.0 + 1 + @logger.debug("waiting #{sleep_time}s after suspend/hibernation") end maintain_worker_count if respawn master_sleep(sleep_time) @@ -441,23 +441,23 @@ class Unicorn::HttpServer # forcibly terminate all workers that haven't checked in in timeout seconds. The timeout is implemented using an unlinked File def murder_lazy_workers - t = @timeout - next_sleep = 1 + next_sleep = @timeout - 1 now = Time.now.to_i WORKERS.dup.each_pair do |wpid, worker| tick = worker.tick 0 == tick and next # skip workers that are sleeping diff = now - tick - tmp = t - diff + tmp = @timeout - diff if tmp >= 0 - next_sleep < tmp and next_sleep = tmp + next_sleep > tmp and next_sleep = tmp next end + next_sleep = 0 logger.error "worker=#{worker.nr} PID:#{wpid} timeout " \ - "(#{diff}s > #{t}s), killing" + "(#{diff}s > #{@timeout}s), killing" kill_worker(:KILL, wpid) # take no prisoners for timeout violations end - next_sleep + next_sleep <= 0 ? 1 : next_sleep end def after_fork_internal -- cgit v1.2.3-24-ge0c7