What is KeepAlive?
KeepAlive refers to a form of communication in networked systems where devices or software periodically exchange signals to verify that the connection between them remains active. At predefined intervals, one side sends KeepAlive signals, which the recipient interprets as a confirmation that the connection is functioning normally. If no KeepAlive signals are received for a certain period of time, the system assumes the connection has been lost and initiates processes such as closing the communication channel, ending the session, or reconnecting.
In TCP, the feature is known as TCP KeepAlive. On the server side, this functionality automatically releases resources tied to connections with clients that have become unreachable. On the client side, TCP KeepAlive enables automatic reconnections, such as when the server's IP address changes due to failover.
In HTTP, a KeepAlive feature is provided to explicitly maintain the TCP connection between the client and server. This reduces the number of TCP connections needed, conserving connection resources and improving performance. When a web page is loaded, not only the main HTML file but also associated assets like images, CSS, and JavaScript files need to be transferred. Normally, transferring these files requires separate TCP connections for each file. However, with KeepAlive enabled, these transfers can be performed over a single TCP connection. While this feature was optional in HTTP/1.0, KeepAlive has been enabled by default since HTTP/1.1.