Keepalive is a mechanism in data transmission with the goals of maintaining a network connection and convincing oneself of the accessibility and function of a communication partner. Keepalives are usually specific packets of a network protocol. A keep-alive signal is often sent at predefined intervals. If no response is received after a signal is sent, it is assumed that the connection is lost, or future data is routed through a different path until the connection is restored. A keep-alive signal can also be used to indicate to the Internet infrastructure that the connection should be maintained. Without a keep-alive signal, NAT-enabled intermediate routers can terminate the connection after a timeout.
Since the sole purpose is to find links that don’t work or to specify connections that should be preserved, keep-alive messages are usually short and don’t take up a lot of bandwidth. However, their exact format and usage will depend on the communication protocol. Other ways of interpreting a lack of response to a keepalive packet can be:
- Re-establishing the network connection with an existing protocol (e.g. resuming a file download, session management for HTTP and VPN connections),
- Reconnecting while restarting the protocol (e.g. sending e-mails via SMTP),
- Final connection abandonment (timeout), i.e. termination of the log with an error message,
- Deleting routing information from routing tables.
In the TCP protocol, keepalives are optional, but if they are included, they must be disabled by default. In addition, keep-alive packets should only be sent if no data or acknowledgment packets have been received for the connection within an interval. This interval must be configurable. The default setting must not be less than two hours. The keep-alive package does not contain any data. There are three parameters related to keepalive:
- The hold time is the amount of time between two keep-alive transfers at rest. The TCP keep-alive interval must be configurable and is set to no less than 2 hours by default.
- The keep-alive interval is the duration between two consecutive keep-alive retries when no acknowledgment of the previous keep-alive transmission is received.
- Keepalive retry is the number of retries that must be performed before declaring that the remote end is unavailable.
If two hosts are connected over a network over TCP/IP, TCP keepalive packets can be used to determine if the connection is still valid and terminate it if necessary.
Advantages of Keepalive
- Reduces latency associated with HTTP transfers
Disadvantages of Keepalive
- Increases memory usage
Settings for Apache
- Keepalive should be turned on
- Keepalive timeout should be set to 1 to 5 seconds
- Keepalive requests should be 100 or more.