CodePark/ questions / TCP connections in depth
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › TCP connections in depth

An app sends many small messages over TCP and sees extra delays of tens of milliseconds, caused by Nagle's algorithm interacting with delayed ACKs. Which socket option turns Nagle's algorithm off?

TCP_NODELAY

TCP_NODELAY turns off Nagle's algorithm. In Node, you set it with socket.setNoDelay(true).

Nagle's algorithm holds back small segments while earlier data is still unacknowledged. It does this so it can combine them into one bigger segment. The receiver may also use a delayed ACK: it waits a little before it acknowledges data. Together, these two waits can add a noticeable delay.

SO_KEEPALIVE is a tempting wrong answer. It turns on probes for idle connections. It has nothing to do with send delays.