Skip to content

Commit

Permalink
Use TCP_NODELAY for improved latency
Browse files Browse the repository at this point in the history
According to the NSQ protocol, consumers have to send `FIN`s for every
message they receive, which makes them extremely slow with low `max_in_flight`
values due to TCP buffering.

Adding TCP_NODELAY option on `async.AsyncConn`'s sockets makes `nsq.Reader`
substantially faster. My tests show increase from ~50 to ~4.5K messages per
second on localhost.
  • Loading branch information
protoss-player committed Mar 28, 2017
1 parent ce384ee commit 50ccce8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ dist
pynsq.egg-info
build
docs/_build
.cache
.eggs
*.dat
*.tmp
1 change: 1 addition & 0 deletions nsq/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def connect(self):

self.stream = tornado.iostream.IOStream(self.socket, io_loop=self.io_loop)
self.stream.set_close_callback(self._socket_close)
self.stream.set_nodelay(True)

self.state = CONNECTING
self.on(event.CONNECT, self._on_connect)
Expand Down

0 comments on commit 50ccce8

Please sign in to comment.