Keep-Alive
Learning Focus
By the end of this lesson you will understand how HTTP keep-alive works, what settings to tune, and how to find the right balance for your traffic.
What Keep-Alive Does
Keep-alive allows multiple HTTP requests over a single TCP connection. Without it, the browser must open a new connection for every resource — each with a TCP handshake and potentially a TLS handshake.
Key Settings
| Setting | What It Does | Recommended Range |
|---|---|---|
| Keep-Alive Timeout | How long to keep an idle connection open | 5-60 seconds |
| Max Keep-Alive Requests | Maximum requests per connection | 1000-10000 |
Tuning Guidelines
| Server Size | Timeout | Rationale |
|---|---|---|
| Small VPS (1-2 GB) | 5-15s | Conserve connections and file descriptors |
| Medium (4-8 GB) | 15-30s | Balance reuse and capacity |
| Large (16+ GB) | 30-60s | Maximize client connection reuse |
Configuring in WebAdmin
- Server Configuration → Tuning → Connection
- Set Keep-Alive Timeout and Max Keep-Alive Requests
- Save and Graceful Restart
Verifying
# Check keep-alive in response headers
curl -sI https://example.com | grep -i "keep-alive\|connection"
Key Takeaways
- Keep-alive reduces handshake overhead by reusing connections for multiple assets.
- Set timeouts high enough to help browsers, but not so high that idle clients waste capacity.
- Modern browsers and HTTP/2 manage multiplexing automatically, but keep-alive remains valuable.
What's Next
- Continue to HTTP/2 for modern protocol multiplexing.