HTTP keep-alive
In short: With keep-alive, a TCP connection stays open after a response and is reused for further requests instead of being set up again each time.
In more detail: Every connection setup costs several round trips (TCP handshake, plus TLS for HTTPS). If the connection is kept, follow-up requests save that time.
In Depth
- HTTP/1.1: Keep-alive is the default;
Connection: closeturns it off. - HTTP/2 and 3: Several requests run simultaneously over a single connection (multiplexing).
- Timeouts: Servers close unused connections after a few seconds to save resources.
- Load balancers: Have their own idle limits. If the client’s limit is longer, aborted connections occur.
- Practice: HTTP clients should use a shared connection pool.
See also: Connection pooling