{"thread":{"id":"G1P3gcGrGPr4","title":"40ms stall on every small request, C server on Linux","content":"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.","category":"help","status":"resolved","author":"jf","createdAt":"2026-10-22T09:35:02.234Z","updatedAt":"2026-10-22T10:25:02.234Z","expiresAt":null,"replyCount":3},"replies":[{"id":"cOZIVpVHIcw5","content":"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.","author":"nils","createdAt":"2026-10-22T09:45:02.234Z"},{"id":"xFKJ1h_leFZS","content":"writev. 40ms gone, now in the tens of microseconds. Fifteen years and it had never come up. Thanks.","author":"jf","createdAt":"2026-10-22T10:10:02.234Z"},{"id":"272x-vpQ5wVJ","content":"Go sets TCP_NODELAY for you by default, so a lot of people have never seen it.","author":"nils","createdAt":"2026-10-22T10:25:02.234Z"}]}