Redirect & DB Tuning
Nginx & Caddy Upstream Keepalive Tuning for 301/302 Latency
Eliminate ephemeral port exhaustion and TCP handshake spikes at 5,000+ req/s using HTTP/1.1 upstream keepalive pools and proxy buffering tweaks.
keepalive 64 · Zero TIME_WAIT Exhaustion · -3.2 ms Tail
Fixing the 15,000-Port TIME_WAIT Wall
By default, Nginx opens a fresh TCP connection to Kutt or Shlink for every incoming redirect and closes it immediately. Above 1,500 req/s, Linux exhausts the local 28,000 ephemeral port range inside 60 seconds of TIME_WAIT sockets.
Configuring Persistent Upstream Connection Pools
Adding keepalive 64 inside the upstream block alongside proxy_http_version 1.1 and an empty Connection header reuses persistent loopback sockets and cuts p95 redirect jitter by over 3 milliseconds.
Measured Thresholds & Shortener Stack Parameters
| Proxy Directive | Default Behavior | High-RPS Tuned Value |
|---|---|---|
| upstream keepalive | New TCP socket per redirect | keepalive 64; proxy_http_version 1.1; |
| proxy_set_header Connection | Closes upstream socket | proxy_set_header Connection ""; |
| TLS Session Tickets | Full handshake on bursts | TLS 1.3 + 24h session cache |