about summary refs log tree commit homepage
path: root/lib/unicorn/configurator.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-30 19:16:43 -0700
committerEric Wong <normalperson@yhbt.net>2009-07-01 13:35:27 -0700
commit563d03f649ef31d2aec3505cbbed1e015493b8fc (patch)
treec08a5605671250f523c6ddc6e2e86d767aeac4b0 /lib/unicorn/configurator.rb
parentd247b5d95a3ad2de65cc909db21fdfbc6194b4c9 (diff)
downloadunicorn-563d03f649ef31d2aec3505cbbed1e015493b8fc.tar.gz
Now that we support tunnelling arbitrary protocols over HTTP as
well as "100 Continue" responses, TCP_NODELAY actually becomes
useful to us.  TCP_NODELAY is actually reasonably portable
nowadays; even.

While we're adding non-portable options, TCP_CORK/TCP_NOPUSH can
be enabled, too.  Unlike some other servers, these can't be
disabled explicitly/intelligently to force a flush, however.
However, these may still improve performance with "normal" HTTP
applications (Mongrel has always had TCP_CORK enabled in Linux).

While we're adding OS-specific features, we might as well
support TCP_DEFER_ACCEPT in Linux and FreeBSD the "httpready"
accept filter to prevent abuse.

These options can all be enabled on a per-listener basis.
Diffstat (limited to 'lib/unicorn/configurator.rb')
-rw-r--r--lib/unicorn/configurator.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 99a3c04..1f18515 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -212,7 +212,24 @@ module Unicorn
     # specified.
     #
     # Defaults: operating system defaults
-    def listen(address, opt = { :backlog => 1024 })
+    #
+    # +tcp_nodelay+: disables Nagle's algorithm on TCP sockets
+    #
+    # This has no effect on UNIX sockets.
+    #
+    # Default: operating system defaults (usually Nagle's algorithm enabled)
+    #
+    # +tcp_nopush+: enables TCP_CORK in Linux or TCP_NOPUSH in FreeBSD
+    #
+    # This will prevent partial TCP frames from being sent out.
+    # Enabling +tcp_nopush+ is generally not needed or recommended as
+    # controlling +tcp_nodelay+ already provides sufficient latency
+    # reduction whereas Unicorn does not know when the best times are
+    # for flushing corked sockets.
+    #
+    # This has no effect on UNIX sockets.
+    #
+    def listen(address, opt = {})
       address = expand_addr(address)
       if String === address
         Hash === @set[:listener_opts] or
@@ -222,6 +239,11 @@ module Unicorn
           Integer === value or
             raise ArgumentError, "not an integer: #{key}=#{value.inspect}"
         end
+        [ :tcp_nodelay, :tcp_nopush ].each do |key|
+          (value = opt[key]).nil? and next
+          TrueClass === value || FalseClass === value or
+            raise ArgumentError, "not boolean: #{key}=#{value.inspect}"
+        end
         @set[:listener_opts][address].merge!(opt)
       end