lib/pitchfork/socket_helper.rb in pitchfork-0.14.0 vs lib/pitchfork/socket_helper.rb in pitchfork-0.15.0
- old
+ new
@@ -24,10 +24,12 @@
# favor latency over bandwidth savings
:tcp_nopush => nil,
:tcp_nodelay => true,
}
+ private
+
# configure platform-specific options (only tested on Linux 2.6 so far)
def accf_arg(af_name)
[ af_name, nil ].pack('a16a240')
end if RUBY_PLATFORM =~ /freebsd/ && Socket.const_defined?(:SO_ACCEPTFILTER)
@@ -62,11 +64,11 @@
seconds = 0 unless seconds # nil/false means disable this
sock.setsockopt(:IPPROTO_TCP, :TCP_DEFER_ACCEPT, seconds)
elsif respond_to?(:accf_arg)
name = opt[:accept_filter]
name = DEFAULTS[:accept_filter] if name.nil?
- sock.listen(opt[:backlog])
+ sock.listen(compute_backlog(opt))
got = (sock.getsockopt(:SOL_SOCKET, :SO_ACCEPTFILTER) rescue nil).to_s
arg = accf_arg(name)
begin
sock.setsockopt(:SOL_SOCKET, :SO_ACCEPTFILTER, arg)
rescue => e
@@ -87,12 +89,20 @@
log_buffer_sizes(sock, "before: ")
sock.setsockopt(:SOL_SOCKET, :SO_RCVBUF, rcvbuf) if rcvbuf
sock.setsockopt(:SOL_SOCKET, :SO_SNDBUF, sndbuf) if sndbuf
log_buffer_sizes(sock, " after: ")
end
- sock.listen(opt[:backlog])
+ sock.listen(compute_backlog(opt))
rescue => e
Pitchfork.log_error(logger, "#{sock_name(sock)} #{opt.inspect}", e)
+ end
+
+ def compute_backlog(opt)
+ backlog = opt[:backlog]
+ if backlog > 0 && opt[:queues]
+ return backlog / opt[:queues]
+ end
+ backlog
end
def log_buffer_sizes(sock, pfx = '')
rcvbuf = sock.getsockopt(:SOL_SOCKET, :SO_RCVBUF).int
sndbuf = sock.getsockopt(:SOL_SOCKET, :SO_SNDBUF).int