HTTP connections long and short links

1, the relationship between the HTTP protocol and TCP / IP protocol

  HTTP connections long, short and long connection is a TCP connection essentially short connection.

  HTTP is an application layer protocol, using the TCP protocol in the transport layer, IP at the network layer.

   IP network routing protocol and addressing mainly to solve the problem, TCP protocol is mainly to solve how to reliably transfer data packets over the IP layer, so that the receiver receives all packets sent by the transmitting end of the network, and is consistent with the order of transmission order.

 

2, HTTP protocol is stateless

  No protocol for transaction processing and memory capacity, the server does not know what the client state. That is to say, open a Web page on a server and open the last time there is no link between the pages on this server.

  HTTP is a stateless connection-oriented protocol, does not mean stateless HTTP TCP connection can not be maintained, but can not represent the HTTP protocol uses the UDP (no connection).

 

3, long connection, short connection

  Default in HTTP / 1.0 in the short connection . In other words, the client and the server once for each HTTP operation, once the connection is established, the task will end disconnected.

  When an HTML Web page or other type of client browser to access the Web contains other resources (such as JavaScript files, image files, CSS files, etc.), when confronted with such a Web resource, the browser will be re-established an HTTP session.

  From the HTTP / 1.1 cases, default long connection for holding the connection characteristics. A long connection using the HTTP protocol, which will be added in response to the first line of code:

Connection:keep-alive

  In the case when TCP long connection, when a page is opened is completed, for the transmission of HTTP data between the client and the server connection is not closed, clients access the server again, we will continue to use a connection has been established .

  Keep-Alive not permanently remain connected, it has a hold time, may be set at this time to a different server software (e.g., Apache) in. Achieve a long connection requires a client and server support long connection.

 

4, a long connection, short connection advantages and disadvantages

  Long connections advantages and disadvantages:

  Long connection can omit TCP build more and closed operations, reduce waste and save time . For customers frequently requested resources, it is more suitable for long connection.

  But there is a problem here, the survival function of the probing cycle is too long, there is just detect it alive TCP connections, are more gentle approach, encountered a malicious connections, keep-alive function is not enough to make up.

  In the long connection of application scenarios, Client-side generally will not take the initiative to close the connection between them is the connection between, Client and server If you have not turned off, there will be a problem, as more and more client connections, server Sooner or later there could not carry the time.

  This time the server side need to take some strategies, such as closing some long time to read and write events connection, connection to avoid malicious damage leading to server-side services; and then if the conditions can allow a client machine to particle size limit the maximum length of connections per client, so you can completely avoid a pain egg hurt the back-end client service.

  Short connections advantages and disadvantages:

  Short connections for the server management simpler , there are useful links are connected, no additional control. However, if the customer requests frequently, we will build on the TCP and closing operation of a waste of time and bandwidth .

Guess you like

Origin www.cnblogs.com/RebeccaG/p/12091939.html