transport

HTTP2 is delivered in binary format, replacing the text format of Http1. x, which is parsed more efficiently.

mechanism

In HTTP/1, each request will establish an HTTP connection, which is often referred to as three handshakes and four waves. This process takes a long time in the process of a request. Keep-alive is enabled in time to solve the problem of multiple connections, but there are still two efficiency problems:

1. The first one is serial file transfer. When file A is requested, file B can only wait for a to connect to the server, the server to process the file, and the server to return the file. Let’s assume that all three steps take 1 second, so file A takes 3 seconds, file B takes 6 seconds to complete, and so on. (Note: there is a prerequisite for this calculation, that is, the browser and the server are single-channel transmission.)

2. The number of connections is excessive. Let’s assume that Apache sets the maximum number of concurrent requests to 300. Because of browser limitations, the maximum number of requests the browser can make is 6, which means the maximum number of concurrent requests the server can handle is 50. When the 51st person visits, the server will have to wait for one of the previous requests to complete.

HTTP/2 multiplexing addresses both of these performance issues.

In HTTP/2, there are two very important concepts: frame and stream. A frame represents the smallest unit of data, and each frame identifies which stream it belongs to. A stream is a data stream composed of multiple frames.

Multiplexing means that multiple streams can exist in a TCP connection. In other words, multiple requests can be sent, and the peer end can know which request belongs to by the identifier in the frame. By using this technique, the queue header blocking problem in older VERSIONS of HTTP can be avoided and the transmission performance can be greatly improved.

In a nutshell:

1. All communication with a domain name is completed on a single connection, eliminating the delay and memory consumption caused by multiple TCP connections.

2. Interleaved requests and responses on a single connection do not interfere with each other.