diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-05-28 11:40:33 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-05-28 11:45:15 -0700 |
commit | bb3d776d8c07f2492ec5a3ef22184f5f59e116c7 (patch) | |
tree | 9b8d59671de7c92578107033a9fc865779c0c44b | |
parent | 18c4ade90959d4eaa0048e83f3ce1052fa8a5905 (diff) | |
download | unicorn-bb3d776d8c07f2492ec5a3ef22184f5f59e116c7.tar.gz |
This should be faster/cheaper than using an instance variable since it's accessed in a critical code path. Unicorn was never designed to be reentrant or thread-safe at all, either.
-rw-r--r-- | lib/unicorn.rb | 7 | ||||
-rw-r--r-- | lib/unicorn/http_request.rb | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 044fed2..d56cb6f 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -41,6 +41,9 @@ module Unicorn # signal queue used for self-piping SIG_QUEUE = [] + # constant lookups are faster and we're single-threaded/non-reentrant + REQUEST = HttpRequest.new + # We populate this at startup so we can figure out how to reexecute # and upgrade the currently running instance of Unicorn START_CTX = { @@ -71,7 +74,6 @@ module Unicorn @config = Configurator.new(options.merge(:use_defaults => true)) @listener_opts = {} @config.commit!(self, :skip => [:listeners, :pid]) - @request = HttpRequest.new(@logger) @orig_app = app end @@ -424,7 +426,7 @@ module Unicorn # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) - HttpResponse.write(client, @app.call(@request.read(client))) + HttpResponse.write(client, @app.call(REQUEST.read(client))) # if we get any error, try to write something back to the client # assuming we haven't closed the socket, but don't get hung up # if the socket is already closed or broken. We'll always ensure @@ -577,6 +579,7 @@ module Unicorn @config.commit!(self) kill_each_worker(:QUIT) Unicorn::Util.reopen_logs + REQUEST.logger = @logger @app = @orig_app build_app! if @preload_app logger.info "done reloading config_file=#{@config.config_file}" diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 368305f..d7078a3 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -12,6 +12,8 @@ module Unicorn # class HttpRequest + attr_accessor :logger + # default parameters we merge into the request env for Rack handlers DEFAULTS = { "rack.errors" => $stderr, @@ -36,7 +38,7 @@ module Unicorn PARSER = HttpParser.new PARAMS = Hash.new - def initialize(logger) + def initialize(logger = Configurator::DEFAULT_LOGGER) @logger = logger end |