Progrider

Programming discussion

Board index
Help · ✓ Resolved

40ms stall on every small request, C server on Linux

Tiny TCP server in C. Requests over loopback take exactly 40ms or very close to it. It's suspiciously consistent. The handler takes microseconds. I write the header and the body in two write() calls.

3 replies

Nagle plus delayed ACK. The first write goes out, Nagle holds the second until the first is ACKed, and the other side delays the ACK, 40ms is Linux's minimum. Either setsockopt TCP_NODELAY, or better, send it all in one write. writev is made for this.
writev. 40ms gone, now in the tens of microseconds. Fifteen years and it had never come up. Thanks.
Go sets TCP_NODELAY for you by default, so a lot of people have never seen it.

Discussion resolved

This discussion is resolved. Its creator can reopen it to accept more replies.