diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index b63abeb..72cda10 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -1,8 +1,17 @@ # -*- encoding: binary -*- require 'fcntl' -require 'unicorn/socket_helper' require 'etc' +require 'unicorn/socket_helper' +require 'unicorn/const' +require 'unicorn/http_request' +require 'unicorn/configurator' +require 'unicorn/util' +require 'unicorn/tee_input' + +# autoload this so the app can prefer a different version, we +# don't rely on Rack itself for much and should be compatible for +# 1.0.x and 1.1.x+ autoload :Rack, 'rack' # Unicorn module containing all of the classes (include C extensions) for running @@ -17,12 +26,10 @@ module Unicorn class ClientShutdown < EOFError end - autoload :Const, 'unicorn/const' - autoload :HttpRequest, 'unicorn/http_request' + # we load HttpResponse last since it depends on Rack, and we + # want the application to be able to specify Rack (if they're + # *not* using config.ru) autoload :HttpResponse, 'unicorn/http_response' - autoload :Configurator, 'unicorn/configurator' - autoload :TeeInput, 'unicorn/tee_input' - autoload :Util, 'unicorn/util' class << self def run(app, options = {}) @@ -395,9 +402,12 @@ module Unicorn # machine) comes out of suspend/hibernation if (last_check + timeout) >= (last_check = Time.now) murder_lazy_workers + else + # wait for workers to wakeup on suspend + master_sleep(timeout/2.0 + 1) end maintain_worker_count if respawn - master_sleep + master_sleep(1) when :QUIT # graceful shutdown break when :TERM, :INT # immediate shutdown @@ -478,9 +488,9 @@ module Unicorn # 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 + def master_sleep(sec) begin - ready = IO.select([SELF_PIPE.first], nil, nil, 1) or return + ready = IO.select([SELF_PIPE.first], nil, nil, sec) or return ready.first && ready.first.first or return loop { SELF_PIPE.first.read_nonblock(Const::CHUNK_SIZE) } rescue Errno::EAGAIN, Errno::EINTR @@ -800,15 +810,15 @@ module Unicorn def build_app! if app.respond_to?(:arity) && app.arity == 0 - # exploit COW in case of preload_app. Also avoids race - # conditions in Rainbows! since load/require are not thread-safe - Unicorn.constants.each { |x| Unicorn.const_get(x) } - if defined?(Gem) && Gem.respond_to?(:refresh) logger.info "Refreshing Gem list" Gem.refresh end self.app = app.call + + # exploit COW in case of preload_app. Also avoids race + # conditions in Rainbows! since load/require are not thread-safe + Unicorn.const_get :HttpResponse end end |