From f65783b5a107fb515b46b17998b276d0fafd4be1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Mar 2009 17:38:01 -0700 Subject: configurator: per-listener backlog, {rcv,snd}buf config Instead of having global options for all listeners, make all socket options per-listener. This allows reverse-proxies to pick different listeners to get different options on different sockets. Given a cluster of machines (10.0.0.1, 10.0.0.2, 10.0.0.3) running Unicorn with the following config: ------------------ 8< ---------------- listen "/tmp/local.sock", :backlog => 1 listen "*:8080" # use the backlog=1024 default ------------------ 8< ---------------- It is possible to configure a reverse proxy to try to use "/tmp/local.sock" first and then fall back to using the TCP listener on port 8080 in a failover configuration. Thus the nginx upstream configuration on 10.0.0.1 to compliment this would be: ------------------ 8< ---------------- upstream unicorn_cluster { # reject connections ASAP if we are overloaded server unix:/tmp/local.sock; # fall back to other machines in the cluster via "backup" # listeners which have a large backlog queue. server 10.0.0.2:8080 backup; server 10.0.0.3:8080 backup; } ------------------ 8< ---------------- This removes the global "backlog" config option which was inflexible with multiple machines in a cluster and exposes the ability to change SO_SNDBUF/SO_RCVBUF via setsockopt(2) for the first time. --- lib/unicorn.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/unicorn.rb') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 34189ef..d56f251 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -59,6 +59,7 @@ module Unicorn @request = @rd_sig = @wr_sig = nil @reexec_pid = 0 @config = Configurator.new(options.merge(:use_defaults => true)) + @listener_opts = {} @config.commit!(self, :skip => [:listeners, :pid]) @listeners = [] end @@ -135,7 +136,7 @@ module Unicorn def listen(address) return if String === address && listener_names.include?(address) - if io = bind_listen(address, { :backlog => @backlog }) + if io = bind_listen(address, @listener_opts[address] || {}) if Socket == io.class @io_purgatory << io io = server_cast(io) -- cgit v1.2.3-24-ge0c7