Keep-Alive Header
What is Keep Alive?
In the HTTP protocol, it allows multiple requests and responses between the client and server to be processed through
a single TCP connectionHTTP operates by establishing a new TCP connection between the client and server for each request and closing the connection after receiving the response
This causes overhead from establishing and terminating connections for each request, which can lead to performance degradation when many requests need to be processed
Keep-Alive is a mechanism introduced to solve this problem, maintaining the connection between the client and server and allowing multiple requests and responses to be processed over the same connection
When the client includes a
"Connection: keep-alive"header in a request, the server can continue sending responses for multiple requests without closing the connection
Starting from
HTTP/1.1, theKeep-Alivefeature, whichreusesalready established TCP connections, is supported by defaultSince the
3-way handshakeprocess is skipped,performance improvementcan be expectedReduces overhead from connection setup and teardown and improves performance by reducing network latency
Keep Alive Characteristics
The Keep-Alive
retention timeis a structure that maintains thesessionfora defined duration from the last I/O access terminationon the connectedsocket, even if there is no accessIn other words, if access occurs within the defined time, the connected state can be maintained
To use the Keep-Alive header, the Connection header must be set to
keep-aliveHowever, in HTTP/2 it is ignored, and connection management is handled by different mechanisms within that protocol
Event-drivenarchitectures that usenon-blocking, such asNginx, do not occupyThreadswhile usingKeep-Alive, making them advantageous forconcurrent processing
Why Set a Keep-Alive Timeout
Server resources are not infinite
Maintaining connections indefinitely causes losses to the server
In other words, the number of
socketsthat can establish connections with the server is limited, and if connections are maintained for too long, it can lead to situations where others cannot connect
Keep-Alive in HTTP/1.0+ and HTTP/1.1
In
1.0+, configuration was neededto useKeep-Alive,In
1.1, configuration is neededto disconnectKeep-AliveIn other words, the purpose of the configuration differs: whether it's for using it or for disconnecting it!
Last updated