diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-03-21 13:31:55 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-03-21 13:53:24 -0700 |
commit | 9a59450a8f8cb415fa11ddbf5bf375c9cb7829d3 (patch) | |
tree | d4ce037661d8ebabebb4cce2b4d711b74fdfbbd5 | |
parent | 46681f6ffd71b0902801f728f8911b02f3f09e1e (diff) | |
download | unicorn-9a59450a8f8cb415fa11ddbf5bf375c9cb7829d3.tar.gz |
Only sleep if our signal queue is empty. Remove redundant exception handling and go back to just consuming the entire pipe since that's more efficient if we're slammed with signals for whatever reason.
-rw-r--r-- | lib/unicorn.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 44d1b6d..2f86de2 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -159,7 +159,7 @@ module Unicorn # are trapped. See trap_deferred @rd_sig, @wr_sig = IO.pipe unless (@rd_sig && @wr_sig) @rd_sig.nonblock = @wr_sig.nonblock = true - ready = mode = nil + mode = nil respawn = true QUEUE_SIGS.each { |sig| trap_deferred(sig) } @@ -173,6 +173,7 @@ module Unicorn when nil murder_lazy_workers spawn_missing_workers if respawn + master_sleep when 'QUIT' # graceful shutdown break when 'TERM', 'INT' # immediate shutdown @@ -206,18 +207,6 @@ module Unicorn else logger.error "master process in unknown mode: #{mode}" end - reap_all_workers - - ready = begin - IO.select([@rd_sig], nil, nil, 1) or next - rescue Errno::EINTR # next - end - ready[0] && ready[0][0] or next - begin - @rd_sig.sysread(1) - rescue Errno::EAGAIN, Errno::EINTR - # spurious wakeup? ignore it - end end rescue Errno::EINTR retry @@ -265,6 +254,17 @@ module Unicorn end end + # wait for a signal hander to wake us up and then consume the pipe + # Wake up every second anyways to run murder_lazy_workers + def master_sleep + begin + ready = IO.select([@rd_sig], nil, nil, 1) + ready && ready[0] && ready[0][0] or return + loop { @rd_sig.sysread(Const::CHUNK_SIZE) } + rescue Errno::EAGAIN, Errno::EINTR + end + end + def awaken_master begin @wr_sig.syswrite('.') # wakeup master process from IO.select |