In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of multiplexing in http2, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Reviewing the http1.1 protocol, we know that although http1.1 implements the long connection of tcp, in a tcp link channel, we can continuously process multiple http request responses, but this process is half-duplex mode, that is, only one request request or response can be processed at a time, and the subsequent request must wait until the previous request response.
In order to load page resources more quickly, browsers set a maximum number of concurrency for the same domain name, which can speed up slightly, but it also brings some problems. See the shortcomings of http1.1 compared to http2 in the previous article.
Http2 completely abandons http1.1 half-duplex communication and realizes full-duplex communication, which is shown as follows: the browser establishes only one tcp connection channel for the resources of the same domain name, and all requests for this domain name are completed in this channel, and the stream mechanism is introduced. This channel can handle multiple request at the same time, which is different from the pepeline,http2 multiplexing of http1.1. The response to request is not blocked because the response from the previous request is not complete, and http2 completely solves the head-of-line blocking at the http level.
All http requests in a tcp channel in http2 will not be blocked, regardless of whether they are first or later. Similarly, multiple resources in a page are requested at the same time. If you use http2 to implement the request, the process is as shown in the figure:
This figure is different from the one in the http1.1 version of the previous article, where you can see that the http request is not blocked because the previous request did not respond.
Let's use a few pictures to demonstrate the evolution of pipeline from http1.1 to http1.1 to http2.
Look at the first picture first:
Looking closely at the above figure, we can see that in a tcp channel in the http1.1 version, this is a single channel, and only one http request can be processed at a time, and must be in order.
Look at the second picture:
Take a closer look at this diagram, although multiple http concurrency is implemented in a tcp channel, but the return will be blocked, who arrives first, who returns first, the order must not be out of order, this is the disadvantage of http1.1pipeline. There is another limitation of pipeline. Only idempotent requests (get, head, etc.) can be applied to pipeline. Most browsers turn off pipeline by default.
Look at the third picture:
In this figure, multiple http requests and responses are made simultaneously in a tcp link channel. Careful observation shows that the request order has nothing to do with the response order, and the speed is significantly faster than the above two images, and the resource requests in the page are completed in a tcp channel, which effectively avoids factors such as tcp racing and slow start.
The above only demonstrates the transmission mode of http2, so how does it achieve it?
Http1.1 is a plaintext protocol, and the plaintext parsing of http1.1 is based on text. Http2.0 's protocol is in binary format.
Why should http2 use binary format?
1. Based on text parsing, there are many forms of expression of the text, and there must be many scenarios to consider the robustness.
2. Binary only recognizes the combination of 0 and 1, so the parsing speed is faster.
So how does HTTP/1.1 transition to http1.1 without changing its semantics, semantics, status codes, URI, partial fields, and so on?
The key is to add a binary framing layer between the HTTP/2 layer and the TCP or UDP layer. As shown in the figure:
In the binary framing layer, HTTP/2 divides all transmitted messages into more expensive messages and encapsulates them in frames (frame), and encodes them in binary format, in which the partial information of HTTP1.1 is encapsulated into HEADER frame, and the corresponding Request Body is encapsulated into DATA frame messages. For example, the HEADER frame and DATA frame in the figure above correspond to the request header and body of http1.1, respectively.
The comparison is shown in the figure:
In addition, HTTP/2 communication is completed on several tcp connections, which will simultaneously process multiple http request,http2 to assign a unique streamId to each http request, and each request-cut fram shares this streamId, so that the http2 can restore the cut information based on this streamid. The way of simultaneously processing multiple request in the http2 channel is similar to processing multiple streams, so some articles will point out that http2 implements stream transmission. As shown in the figure:
In the figure above, each large blue box represents a http request, and each request is cut into multiple fream, and is numbered. We use yellow, red and green to represent three stream streams respectively. Different colors represent different streamid,http2 receiving data will automatically restore data according to its streamid, thus realizing streaming transmission in a TCP connection channel, and multiple request will reuse this TCP channel to achieve efficient reuse.
Thank you for reading this article carefully. I hope the article "sample Analysis of Multiplexing in http2" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.