about summary refs log tree commit homepage
diff options
context:
space:
mode:
authornormalperson <normalperson@19e92222-5c0b-0410-8929-a290d50e31e9>2008-03-02 02:34:53 +0000
committernormalperson <normalperson@19e92222-5c0b-0410-8929-a290d50e31e9>2008-03-02 02:34:53 +0000
commitcf4c3f142c4403f3eb1bad4baedf58ec9247d1e5 (patch)
tree3a57c3813bf193aff2515f08c5d9af948cd033d6
parent255c8fb5aebba36cf4e4cf03810c919135c5ee5a (diff)
downloadunicorn-cf4c3f142c4403f3eb1bad4baedf58ec9247d1e5.tar.gz
Since we're going to close the socket immediately after the
num_processors limit is reached, there's no point in calling
setsockopt(2) to enable TCP_CORK on it.  Instead, only enable
TCP_CORK for connections we are able to handle.

Additionally, avoid calling worker_list.length twice in the
connection rejected case and instead just set num_workers to
@workers.list.length once.  I'm assuming the original
caching of worker_list = @workers.list to avoid having
the log message display a different number due to a race
condition; and this preserves that functionality.


git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@988 19e92222-5c0b-0410-8929-a290d50e31e9
-rw-r--r--lib/mongrel.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 15d5aee..b06e071 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -276,18 +276,16 @@ module Mongrel
           while true
             begin
               client = @socket.accept
-  
-              if defined?($tcp_cork_opts) and $tcp_cork_opts
-                client.setsockopt(*$tcp_cork_opts) rescue nil
-              end
-  
-              worker_list = @workers.list
-  
-              if worker_list.length >= @num_processors
-                Mongrel.log(:error, "#{Time.now.httpdate}: Server overloaded with #{worker_list.length} processors (#@num_processors max). Dropping connection.")
+
+              num_workers = @workers.list.length
+              if num_workers >= @num_processors
+                Mongrel.log(:error, "#{Time.now.httpdate}: Server overloaded with #{num_workers} processors (#@num_processors max). Dropping connection.")
                 client.close rescue nil
                 reap_dead_workers("max processors")
               else
+                if defined?($tcp_cork_opts) and $tcp_cork_opts
+                  client.setsockopt(*$tcp_cork_opts) rescue nil
+                end
                 thread = Thread.new(client) {|c| process_client(c) }
                 thread[:started_on] = Time.now
                 @workers.add(thread)