Commit b4a45ab
Marko Petzold
router/websocket: expose TCP send/recv buffer + Nagle knobs on the server
WebsocketServer gains three optional fields applied to each accepted
connection's underlying *net.TCPConn after the WebSocket upgrade:
- TCPSendBufferBytes int → SO_SNDBUF
- TCPRecvBufferBytes int → SO_RCVBUF
- EnableNagle bool → leaves TCP_NODELAY off
Defaults are unchanged (zero / false → use OS defaults / NODELAY on),
so behavior is preserved for existing deployments. Useful for
high-fan-out broker scenarios:
Larger SO_SNDBUF reduces the rate at which kernel-side back-pressure
parks per-subscriber send goroutines under sustained load — visible
in pprof as time spent in syscall.Write returning EAGAIN.
Re-enabling Nagle (i.e. NoDelay = false) lets the kernel coalesce
successive small writes into fewer TCP packets — fewer syscalls,
fewer packets, at the cost of tens of ms added latency per write.
Whether this is a win depends on the latency budget; off by default.
setsockopt failures are logged but not fatal so a non-TCP transport
(e.g. unix-domain sockets via a custom Upgrader) still works.1 parent 2009c20 commit b4a45ab
1 file changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
106 | 124 | | |
107 | 125 | | |
108 | 126 | | |
| |||
353 | 371 | | |
354 | 372 | | |
355 | 373 | | |
| 374 | + | |
| 375 | + | |
356 | 376 | | |
357 | 377 | | |
358 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
359 | 408 | | |
360 | 409 | | |
361 | 410 | | |
| |||
0 commit comments