About the long connection of HTTP1.1

Source: Internet
Author: User
Tags ftp protocol

HTTP is an application layer protocol built on the TCP protocol of the Transport layer, in which the Protocol is a protocol specification that network interaction needs to comply with.

Short connection of HTTP1.0

HTTP 1.0 Specifies that the browser only maintains a brief connection with the server. Each browser request requires a TCP connection to the server, and the server disconnects the TCP connection immediately after the request is processed, and the server does not track each customer and does not log past requests. This process can probably describe the narrative as:

1, establish the connection: first DNS parsing process. such as the domain name into an IP. Assuming the URL does not include the port number, the default port number of the protocol is used, and the default port number for the HTTP protocol is 80. Then a three-time handshake establishes a TCP connection;

2. Request: After successful connection, start sending request to webserver. This request is usually a GET or POST request.

3, Answer: Webserver received this request, processing. Webserver will send the contents of the file to the responding Web browser. Includes: HTTP header information, body information.

4. Close the connection: When the answer is finished, the Web browser and webserver must have four handshake disconnects to ensure that the other Web browser is able to establish a connection with the webserver.

Long connection of HTTP1.1

But HTTP1.1 started by default a long connection, that is, once the browser initiates an HTTP request, the established connection does not request an answer and immediately disconnects.

1. How many TCP connections will be established for a complex web page with very many HTTP resources, and how to use these connections?

2. Whether the established TCP connection will be disconnected on its own initiative. How long is the time?

For the first question. Browsers now have a maximum number of concurrent connections. It should be said that if necessary, we will try to establish a lot of other TCP persistent connections within the agreed scope to handle HTTP requests, the same drops. A TCP persistent connection can continuously transmit multiple HTTP requests. However, assuming that the response from the previous request has not yet been received, the next request cannot be processed (pipeling pipeline technology can solve the problem to further improve performance), so many browsers can actually change the number of concurrent connections that agree to maximize the speed of browsing the web.

For a second question.

The problem is the server-side implementation of long connections, especially in the maintenance of long connections.

The FTP protocol and the SMTP protocol have NOOP messages, which can be thought of as heartbeat messages. However, the HTTP protocol does not have similar messages, so the server can only maintain the connection using a policy that has a time-out break.

Imagine a very short time-out. Then the effective spare time is very short. In other words: Once there is no data sent on the link, the server closes the connection very quickly.

In fact, the long connection of HTTP is very easy to spare after the active disconnection, generally this time is about 300s.

References

=====================================================================

1, HTTP1.1 enhance the performance of means

Copyright belongs to all authors.


For commercial reprint please contact the author for authorization. Please specify the source for non-commercial reprint.
Saviio
Links: http://www.zhihu.com/question/36469741/answer/67608570
Source: Know

HTTP1.1 has probably standardized several ways to raise performance:

    1. Persistent connection (keep-alive/persistent connection)
    2. Parallel connections
    3. Pipelining

The 1th has been said before, so no table.

2nd. Since modern web pages typically include multiple (>=10) resources, and by default, each request in a connection must wait for a response to be sent to the next request, so it would be very slow to assume that all of the complex resource requests are sent to the server in a single by one connection. To compensate for this flaw, browsers typically open multiple TCP connections by default, and then send data requests in turn based on the status of each connection, and the client has the right to turn off the hyper-send connection at will. The number of parallel connections that each browser agrees on is roughly the same (from so):

Firefox 2:2

Firefox 3 +: 6

Opera 9.26:4

Opera 12:6

Safari 3:4

Safari 5:6

IE 7:2

IE 8:6

IE 10:8

Chrome:6

Because the TCP protocol itself has a slow-start feature, the maximum speed of the connection is tuned over time, so persistent connections and parallel connections in modern browsers are often used together-on the one hand, due to the existence of persistent connections. Each TCP connection is already in a tuned state. There is also one aspect of persistent connection that avoids the overhead of another three handshake.

On the 3rd,
According to HTTP1.1 's descriptive narrative. There is also the ability to improve the performance of the solution is pipelined. The ability to send multiple requests in one connection does not have to wait for the previous request to return.

But this technology is easier to step on the pit, so the mainstream user-oriented browser, this technology is closed by default.

About HTTP2:
HTTP2 has done a lot of work for performance, such as providing specifications to support multiplexing of connections.


HTTP1.0 need to add keep-alive request header. Otherwise, the default one requests a connection.


Keep-alive (persistent connection) is enabled by default after HTTP1.1, unless Connection:close is specified in the response, Webserver assumes that all connections are persistent.

=====================================================================

Ge Jiaxiang . Program Ape /phper/ Open source enthusiast

Shi Jianwen , little loneliness. , user-aware and others agree.

@Saviio There is no positive answer to this question. Just a Good understanding of persistent connections in HTTP.

on the landlord's question: Assuming that the first request is complete, then the second request sent. is a 1 tcp connection. The assumption is that two requests start at the same time, or the first request is not finished, and the second request, which is two TCP connections, is started .



because HTTP the protocol is synchronous and does not have multiplexing support. A pipe can only do one thing at a time.



It 's just lucky that modern computers don't care about a few TCP connected, the protocol is simple, in fact, quite good.


=============================================================

2. About Firefox HTTP settings for the number of parameters:  
related parameters of About:config network.http.*
Network.http.keep-alive Default is true whether to agree to a persistent connection. This default is true, and it is a big fool to change to false.
Network.http.keep-alive.timeout Default is the 300 persistent connection agreed to hold the time, this increase is meaningless, because the general server set is 300.

What else can you do if the server clicks you?
Network.http.max-connections-per-server Default is 8 the maximum number of connections that the same server agrees to connect to. It is generally felt that it is useless to turn this value on and off in the case of a persistent connection, and it is not very ethical. The need for a larger case analogy: you are at the same time from the site under the 10 large files.
Network.http.max-persistent-connections-per-server Default is 2 The maximum number of persistent connections that the same server agrees to, and the value http/1.1 standard recommended is 2. Increase your network consumption instead of adding your own. and generally a server agreed with the number of persistent connections is limited, you can increase the size of the possible to reduce the availability of others, assuming that everyone is large, it means the loss of network efficiency. I personally recommend not to move this value.


Network.http.pipelining default is false whether to agree with pipelining, this function because of the current or experimental phase, so the default is not open.

It is highly recommended to open.
Network.http.pipelining.maxrequests Default is 4 the number of requests that each persistent connection agrees to send at one time. Suppose pipeline has a large picture or a script that takes longer to execute, the request that is sent later is blocked (note that the server must respond to the request in turn); Assuming that no pipelining is used, the browser discovers a request processing time is very long. Naturally, a persistent connection is used as a request, or even a non-persistent connection is opened further.

Also, assuming that the server supports pipelining bad and prematurely closes the connection, the browser is bound to send the request again. Based on this kind of reason. Some people think that this number is set larger than 2 will slow down the browsing speed. My personal recommendation is that this value will keep the default value of 4. Assume that the site you are browsing has a large number of static small images. Or the network speed is slow. Can try to make it bigger.
Network.http.max-persistent-connections-per-proxy default is 4 maximum number of persistent connections per proxy server consent.

4 is the most appropriate value at the moment. Although the recommended value for http/1.1 is 2.


Network.http.proxy.keep-alive Default is True if the Connection Broker server agrees to a persistent connection. True is very good.


Network.http.proxy.pipelining defaults to False if the Connection Broker server agrees with Pipelining. It is now generally felt that most proxy server support pipelining is not good. Therefore, it is generally not recommended to open.
Pipelining is now a controversial one. Characteristics that are still in the experimental phase.

While it may indeed speed up browsing, this depends in part on the factors of the network, so do not blindly follow the online recommendations to set the relevant parameters.

============================================================

3, explain the browser maximum number of concurrent connections

When we browse the Web, there is an important factor in the speed of browsing, which is the number of concurrent browsers. The number of concurrent numbers is simply that when the browser Web page is working at the same time.

Suppose that at the same time there is only 2 Number of concurrent connections, which can only be relied upon when the page is opened 2 thread, which is preceded by a slow-open content, will directly affect the subsequent opening of the content. But suppose there are many other concurrent connections at the same time. This will greatly improve the speed of page loading. For more information, check out our previously published article: the number of concurrent connections to the browser loading speed test .

The number of concurrent connections in a browser is not as big as possible.

The following table summarizes what is performed on the host based on the IE The maximum number of concurrent connections for the version number of the browser, the connection speed of the host, and the supported protocol version number for the server.

<>

http 1.0 server (Broadband connection)

http 1.1 server (broadband connection)

http 1.0 server (Dial-up connection)

http 1.1 server (Dial-up connection)

Internet Explorer 7 and earlier version numbers

4

2

4

2

Internet Explorer 8

6

6

4

2

Internet Explorer 9

10

10

?

?

Internet Explorer 10

6

6

?

?

Internet Explorer 11

6

6

?

?

Chrome , Firefox

6

6

?

?

InternetExplorer 8+ provides a  window. MaxConnectionsPerServer object that the server can use to determine the number of connections available on the client computer.

in theInternet Explorer 8+the. MaxConnectionsPerServerfor broadband connections will return 6. This default value is overridden by the user or administrator. when a client computer passes a dial-up connection, it is assumed to connect toHTTP 1.1Server, youMaxConnectionsPerServerwill return 2; Suppose you connect toHTTP 1.0Server, youMaxConnectionsPerServerwill return 4.

A lot of people say:

Actual situation ( China ):

Very many client software can change the computer's maximum number of connections. For example: Thunder, Storm Audio and so on.

we've shared this with everyone before. How to change IE number of concurrent connections for the browser , let's say you're using IE7 and the lower version number below, it's a good idea to try to change the number of connections to 6 , which will help speed up the opening of the site.

About the long connection of HTTP1.1

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.