005_ about maintaining connections in the HTTP protocol

Source: Internet
Author: User

Origin

It is discussed in the group at noon, ab why a large number of states are generated when testing a static file service and not interacting with any other system TIME WAIT .

First, we can simply understand that at both ends of the TCP connection, who actively disconnects (first sending the FIN packet), who enters, who is TIME WAIT passive disconnected (after sending FIN the package), who enters the CLOSE WAIT state.

So, it can be inferred that in this scenario, the server is actively disconnected from the party, then why the server is actively disconnected, this involves HTTP in the content of the keepalive.

We often hear about keepalive improving the performance of webserver, but why? For the moment, it is clear that the following content is not explained.

Analysis

In the HTTP protocol, in addition to the need for server support and open keepalive, there is an important request header Connection to note.

Let's take a look at the following request:

GET /? HTTP/1.1Accept: */*Cache-Control: no-cacheConnection: closeHost: 127.0.0.1User-Agent: Apache-HttpClient/4.3.2 (java 1.5)Accept-Encoding: gzip,deflate

This is a request that I send through the rest Client plugin of idea, and we see that the value of the Connection header is close , grab the packet and look at the request process

As you can see, after the server response is complete, a packet is sent and the FIN connection is actively disconnected, which is well understood.

Look at a request:

GET /? HTTP/1.1Accept: */*Cache-Control: no-cacheConnection: keep-aliveKeep-Alive: 5Host: 127.0.0.1User-Agent: Apache-HttpClient/4.3.2 (java 1.5)Accept-Encoding: gzip,deflate

As you can see, the value in this request is changed to a Connection keep-alive Keep-Alive header with a value of 5. Grab the bag and look at this request:

You can see that after the response is completed, the server does not send the FIN package to close the connection, but after a period of time, the client sends the FIN package, closes the connection, and if you look at the second column, time will find that exactly is about 5 seconds after the client sends the FIN packet, this value is Keep-Alive exactly The value of the header. In fact, Keep-Alive the semantics of the head is how many seconds the client stays connected.

The above test, the server with the keepalive are 65s , we come to put it 0, again to test again to see.

Connectionthe client header is close the case:

Connectionthe client is keep-alive , Keep-Alive for 5 the case

As you can see, the server is actively disconnecting.

The last scenario, the server configuration keepalive is 3, the client Connection is keep-alive , Keep-Alive for 5 the case

As you can see, the 3 server sends an active disconnect after the request ends approximately seconds (the primary timestamp) FIN .

Conclusion

Said so much, it is time to summarize, about keepalive mainly have a few points:

    • ConnectionThe head control client is turned on, close not on, keep-alive open
    • Keep-AliveThe head controls when the client remains connected
    • At keepalive the time of opening, who first to keep the connection time, who first sends the FIN package, actively closes the connection.

005_ about maintaining connections in the HTTP protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.