A small request/response RPC protocol shows exactly ~40 ms extra latency per call, but only for some message sizes.
AdvancedTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer
Likely causes → Nagle's algorithm interacting with delayed ACKs. The sender writes a request in two small write()s; Nagle holds the second segment until the first is ACKed, and the receiver delays its ACK (up to 40 ms on Linux) waiting for more data. Result: a 40 ms stall.
Diagnose →
sudo tcpdump -ni eth0 -ttt host <peer> and port 7000
# look for ~0.040000 s gaps between a small segment and the next one
strace -f -e trace=write,sendto -p <pid> # multiple small writes per message?
Fix → Set TCP_NODELAY on the socket (most HTTP and gRPC libraries already do), and coalesce writes into one buffer per message (writev or a buffered writer).
Prevent → Treat any repeated 40 ms or 200 ms latency step as a Nagle/delayed-ACK red flag; include p99 latency checks in protocol tests.
More on Sockets, ports, TIME_WAIT and conntrack
`dmesg` is full of `nf_conntrack: nf_conntrack: table full, dropping packet` and new connections randomly time out.Intermediate`ss -s` on a reverse proxy shows 40,000 sockets in `TIME_WAIT`. Is that a problem?BeginnerAn app server's `CLOSE_WAIT` count grows steadily until the service logs `Too many open files`.IntermediateLogs show `accept4(): Too many open files` and the service stops accepting connections.Beginner`dmesg` shows `TCP: request_sock_TCP: Possible SYN flooding on port 443. Sending cookies.`Intermediate`ss -ltn` shows the listener for port 8080 with `Recv-Q 129` and `Send-Q 128`, and clients hang on connect.Advanced