From 62ebc930c6e3b46cd200212748800c1ca448eb1f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Apr 2009 01:16:35 -0700 Subject: Remove _all_ non-POSIX socket options Unicorn is strictly for fast LAN and localhost clients. Unicorn is not for slow, high-latency or trickling clients and cannot do keepalive or pipelining. None of the removed options actually make sense in the environment Unicorn was designed for. * DEFER_ACCEPT/ACCEPT_FILTER - these are useful for mitigating connect() floods or trickling clients. We shouldn't have to deal with those on a trusted LAN. * TCP_CORK/TCP_NODELAY - we only send output in the response and then immediately close the socket. Assuming the typical response containing a small header and large strings in the body: the Nagle algorithm would've corked the headers regardless and any pending output would be immediately flushed when the socket is closed immediately after sending. These options would still be useful from the client-side on the LAN, or if Unicorn supported keepalive. Of course, I highly recommend enabling all of these options you can possibly enable on nginx or another fully-buffering reverse proxy when dealing with slow clients. --- lib/unicorn.rb | 1 - lib/unicorn/socket.rb | 38 -------------------------------------- 2 files changed, 39 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index fd66529..4e82ec6 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -404,7 +404,6 @@ module Unicorn # in 3 easy steps: read request, call app, write app response def process_client(client) client.nonblock = false - set_client_sockopt(client) if TCPSocket === client env = @request.read(client) app_response = @app.call(env) HttpResponse.write(client, app_response) diff --git a/lib/unicorn/socket.rb b/lib/unicorn/socket.rb index 4cb8d48..f0c41cf 100644 --- a/lib/unicorn/socket.rb +++ b/lib/unicorn/socket.rb @@ -1,30 +1,6 @@ require 'socket' require 'io/nonblock' -# non-portable Socket code goes here: -class Socket - module Constants - # configure platform-specific options (only tested on Linux 2.6 so far) - case RUBY_PLATFORM - when /linux/ - # from /usr/include/linux/tcp.h - TCP_DEFER_ACCEPT = 9 unless defined?(TCP_DEFER_ACCEPT) - TCP_CORK = 3 unless defined?(TCP_CORK) - when /freebsd(([1-4]\..{1,2})|5\.[0-4])/ - when /freebsd/ - # Use the HTTP accept filter if available. - # The struct made by pack() is defined in /usr/include/sys/socket.h - # as accept_filter_arg - unless `/sbin/sysctl -nq net.inet.accf.http`.empty? - unless defined?(SO_ACCEPTFILTER_HTTPREADY) - SO_ACCEPTFILTER_HTTPREADY = ['httpready',nil].pack('a16a240').freeze - end - - end - end - end -end - class UNIXSocket UNICORN_PEERADDR = '127.0.0.1'.freeze def unicorn_peeraddr @@ -42,11 +18,6 @@ module Unicorn module SocketHelper include Socket::Constants - def set_client_sockopt(sock) - sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) if defined?(TCP_NODELAY) - sock.setsockopt(SOL_TCP, TCP_CORK, 1) if defined?(TCP_CORK) - end - def set_server_sockopt(sock, opt) opt ||= {} if opt[:rcvbuf] || opt[:sndbuf] @@ -56,15 +27,6 @@ module Unicorn log_buffer_sizes(sock, " after: ") end sock.listen(opt[:backlog] || 1024) - return if sock_name(sock)[0..0] == "/" - - if defined?(TCP_DEFER_ACCEPT) - sock.setsockopt(SOL_TCP, TCP_DEFER_ACCEPT, 1) rescue nil - end - if defined?(SO_ACCEPTFILTER_HTTPREADY) - sock.setsockopt(SOL_SOCKET, SO_ACCEPTFILTER, - SO_ACCEPTFILTER_HTTPREADY) rescue nil - end end def log_buffer_sizes(sock, pfx = '') -- cgit v1.2.3-24-ge0c7