Skip to content

Commit 419eee8

Browse files
bushidocodesclaude
andauthored
fix: deepen TCP listen backlog to cut connection-setup tail latency (#395)
A single listener thread accepts every client connection. Under a burst of short-lived, non-keep-alive requests (e.g. the concurrency experiment driving the empty workload), the 128-entry accept queue overflows, the kernel drops the connection, and the client only retries after the ~1s initial SYN RTO -- producing a sharp ~1s tail-latency spike. Raise the listen backlog to 4096. The kernel silently caps it to /proc/sys/net/core/somaxconn, so requesting more than the host allows is harmless. Drop the now-redundant compile-time truncation warning and explain the rationale in the comment. Verified with hey against the empty workload at c=200, 50k requests: backlog 128 : p99.9=1084ms, max=1109ms, 202 requests >1s backlog 4096: p99.9= 283ms, max= 292ms, 0 requests >1s At c=1..100 the tail was already clean in both cases (no >1s); this removes the spike that appears once the connection-setup burst exceeds the old backlog. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 309771a commit 419eee8

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

runtime/include/tcp_server.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@
1313
#include "likely.h"
1414

1515
/*
16-
* Defines the listen backlog, the queue length for completely established socketeds waiting to be accepted
17-
* If this value is greater than the value in /proc/sys/net/core/somaxconn (typically 128), then it is silently
18-
* truncated to this value. See man listen(2) for info
16+
* Defines the listen backlog: the queue length for completely established sockets waiting to be accepted.
17+
* The kernel silently caps this to /proc/sys/net/core/somaxconn, so requesting more than the host allows is
18+
* harmless (it just truncates). We request a large value because a single listener thread accepts every
19+
* connection; under a burst of short-lived, non-keep-alive requests a small backlog overflows, the kernel
20+
* drops the connection, and the client only retries after the ~1s initial SYN RTO — a sharp ~1s tail-latency
21+
* spike. A deeper backlog absorbs the burst and removes that spike.
1922
*
20-
* When configuring the number of sockets to handle, the queue length of incomplete sockets defined in
21-
* /proc/sys/net/ipv4/tcp_max_syn_backlog should also be considered. Optionally, enabling syncookies removes this
22-
* maximum logical length. See tcp(7) for more info.
23+
* The queue length of incomplete (half-open) sockets in /proc/sys/net/ipv4/tcp_max_syn_backlog should also be
24+
* considered; enabling syncookies removes that maximum. See listen(2) and tcp(7).
2325
*/
24-
#define TCP_SERVER_MAX_PENDING_CLIENT_REQUESTS 128
25-
#if TCP_SERVER_MAX_PENDING_CLIENT_REQUESTS > 128
26-
#warning \
27-
"TCP_SERVER_MAX_PENDING_CLIENT_REQUESTS likely exceeds the value in /proc/sys/net/core/somaxconn and thus may be silently truncated";
28-
#endif
26+
#define TCP_SERVER_MAX_PENDING_CLIENT_REQUESTS 4096
2927

3028
/* L4 TCP State */
3129
struct tcp_server {

0 commit comments

Comments
 (0)