Network basis: HTTP (3): keep-alive of HTTP

1. Generation
In the early HTTP/0.1, each http request had to create a link, and the process of creating a link required resources and time. In order to reduce resource consumption and shorten response time, it was necessary to reuse connections. In the later HTTP/1.0 and HTTP/1.1, a mechanism for reusing connections was introduced, that is, Connection: Keep-alive was added to the HTTP request header to tell the other party that the request should not be closed after the response is completed. Next time, we can still Use this request to continue communication. The protocol stipulates HTTP/1.0. If you want to maintain a long connection, you need to add Connection: Keep-alive to the request header. In HTTP1.1, Connection: keep-alive is enabled by default, which makes up for the shortcomings of HTTP1.0 that a connection must be created for each request.

2. Advantages Advantages of
Keep-alive:

1. Less CPU and memory usage (due to fewer simultaneous open connections)

2. Allow HTTP pipelining of requests and responses

3. Reduce congestion control (reduction of TCP connections)

4. Reduce the delay of subsequent requests (no need to perform handshake)

5. No need to close TCP connection to report errors

Guess you like

Origin blog.csdn.net/imagine_tion/article/details/110367849