Interview Prep/Networking/Sockets, ports, TIME_WAIT and conntrack

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.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack