Holding Connections Open
A keep alive setting lets a connection stay open after a response so the next request can reuse it. Tuning how long it stays open trades reuse against the cost of holding idle resources.
The Two Sided Choice
Both ends have a say, and the shorter timeout wins.
- A longer idle timeout means more requests can reuse the connection, saving setup.
- A shorter timeout frees server slots faster, which matters when many clients connect.
- A maximum request count can also cap how many requests one connection serves.
If a client expects a connection to stay open but the server closed it, the next write fails and must retry on a fresh connection.
Matching the Two Ends
Mismatched timeouts cause subtle errors, such as a client reusing a connection the server just dropped. Aligning the client idle time to be a little under the server timeout avoids racing against the close.
Key idea
Keep alive tuning sets how long an idle connection lingers, trading reuse against held resources, and aligning the client idle time just under the server timeout avoids racing against a close.