From 19cbfe209a0f9d64e9faade1549c1b9910bf35f7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 28 May 2009 12:00:52 -0700 Subject: Avoid instance variables lookups in a critical path Make us look even better in "Hello World" benchmarks! Passing a third parameter to avoid the constant lookup for the HttpRequest object doesn't seem to have a measurable effect. --- lib/unicorn.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index d56cb6f..8a74f97 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -425,8 +425,8 @@ 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))) + def process_client(app, 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 @@ -487,6 +487,7 @@ module Unicorn trap(:QUIT) { alive = nil; LISTENERS.each { |s| s.close rescue nil } } [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown @logger.info "worker=#{worker.nr} ready" + app = @app begin nr < 0 and reopen_worker_logs(worker.nr) @@ -504,7 +505,7 @@ module Unicorn ready.each do |sock| begin - process_client(sock.accept_nonblock) + process_client(app, sock.accept_nonblock) nr += 1 t == (ti = Time.now.to_i) or alive.chmod(t = ti) rescue Errno::EAGAIN, Errno::ECONNABORTED -- cgit v1.2.3-24-ge0c7