Skip to content


Ensure TCP_NODELAY is disabled by fixing namespacing #187

merged 1 commit into from

2 participants


While using bunny-1.1.0, we discovered an unacceptable latency for publishing messages with confirmation. Between a Bunny client and broker, both running Ubuntu Precise, this latency converges to 40ms for the case of many small messages. After some head-scratching, a packet capture revealed the true cause:

screen shot 2014-02-09 at 10 39 26 pm

Although both frames are sent in a tight loop, the client machine waits for an ACK before sending the payload. This suggests that Bunny isn't disabling Nagle's algorithm as a read through implies it ought to. After some poking, I discovered the bug:

     ::Socket.constants.include?(:TCP_NODELAY)  # => true
Bunny::Socket.constants.include?(:TCP_NODELAY)  # => false

By monkey-patching the implementation, I was able to achieve the desired result:

statsd airbnb

@michaelklishin michaelklishin merged commit 7f57ef8 into ruby-amqp:master

1 check was pending

Details default The Travis CI build is in progress
@michaelklishin michaelklishin added a commit to michaelklishin/sneakers that referenced this pull request
@michaelklishin michaelklishin Bump Bunny to 1.1.3+
[Significantly lower latency](ruby-amqp/bunny#187) for workloads that involve frequently sent small messages.
@michaelklishin michaelklishin referenced this pull request in jondot/sneakers

Bump Bunny to 1.1.3+ #27

@michaelklishin michaelklishin pushed a commit to gocardless/hutch that referenced this pull request
Michael Klishin Bunny 1.1.3+
[Lower latency](ruby-amqp/bunny#187), you see.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2014
  1. @nelgau
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/bunny/cruby/socket.rb
2 lib/bunny/cruby/socket.rb
@@ -16,7 +16,7 @@ class Socket < TCPSocket
def, port, options = {})
Timeout.timeout(options[:socket_timeout], ClientTimeout) do
sock = new(host, port)
- if Socket.constants.include?('TCP_NODELAY') || Socket.constants.include?(:TCP_NODELAY)
+ if ::Socket.constants.include?('TCP_NODELAY') || ::Socket.constants.include?(:TCP_NODELAY)
sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, true)
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true) if options.fetch(:keepalive, true)
Something went wrong with that request. Please try again.