Article tone
- Not a popular science article, not a popular science http2 function article
- Record the incomprehensible points in http2, which is the author's confusion when learning http2, and has finally understood
It is a personal understanding, there may be imprecise places, welcome to discuss
How to understand the difference between TCP framing and http2 framing
- Assuming that "transmitting complete data" is "transporting one order goods", each "one goods in the order" occupies "one freight car"
TCP is located at the transport layer and can be understood as a truck transported by
- Each frame in the TCP is ordered, and the trips are marked according to the departure time, the first trip, the second trip, the third trip, and the Nth trip
- TCP can send several vehicles at the same time. Assuming 4 vehicles, there will be one departure, the first time, the second time, the third time, and the fourth time.
- Each car arrives early, and some arrives slowly, not necessarily arriving at the destination in the order of departure
- When one of the trains returns, the next train will be issued.
- The function of the trips is that the goods can be rearranged in order when they are delivered to the destination. Each trip can be understood as the parts of the Gundam model (only one part is transported in a car), and the order can be recognized and reassembled.
- The goods in an order are transported through different times, which is "TCP binary framing", and the goods (complete data) of the order are divided into each car (frame) for transportation
HTTP is in the application layer, an http request and response can be understood as the process of placing an order (request) to purchase a batch of goods (response), ( note that it is a batch, there are several goods ) and this batch of goods does not have a product name ( cannot correspond to which order this shipment corresponds to, and cannot associate the response with the request )
- At this time, http has not been framed, and the granularity is in units of orders, and an order is an http
- Understand a TCP link as a contract of carriage
http0.9,1.0
[Question] It is very troublesome to sign a transportation contract for every order.- Sign a transportation contract (three-way handshake)
- place an order (request)
- Production goods (server calculation result)
- Initiate transport (TCP transfer content)
- Receipt (response)
- Settle the account of the transportation contract once (waves four times)
- Sign a transportation contract (three-way handshake)
- place an order (request)
- Production goods (server calculation result)
- Initiate transport (TCP transfer content)
- Receipt (response)
- Settle the account of the transportation contract once (waves four times)
http1.1 keep-alive
[Improved] Change the transportation contract to monthly settlement, reuse the TCP link
[Problem] The factory cannot produce goods for multiple orders at the same time, and the previous order needs to be received- Sign a transportation contract (three-way handshake)
- place an order (request)
- Production goods (server calculation result)
- Initiate a shipment (transfer content)
- Receipt (response)
- place an order (request)
- Production goods (server calculation result)
- Initiate a shipment (transfer content)
- Receipt (response)
- Settle the account of the transportation contract once (waves four times)
http1.1 pipeline
[Improved] Multiple orders can be sent at the same time, and the order of receipt can be used to identify the content of that order.
[Improved] The factory can produce multiple orders at the same time
[Question] There is a dependency on the order. Even if the goods of the second order are produced, the goods of the first order cannot be shipped until the goods of the first order are produced and all transmitted. Otherwise, it will be regarded as the first order of- Sign a transportation contract (three-way handshake)
- Place an order (first request)
- Place an order (second request)
- Simultaneous production of the first batch and the second batch of goods (calculated by the server)
- Shipment of the first order in order (transmission content)
- Receive goods in order (response, corresponding to the first response)
- In-sequence shipping of the second order (transfer content)
- Receive goods (response, corresponding to the second response)
- Settle the account of the transportation contract once (waves four times)
http2
[Improved] Split an order's goods into multiple batches, and identify which order's goods are on each batch
[Improved] Since it can identify the order to which a batch of goods belongs, the minimum granularity is changed from one order to one batch. Originally shipped by order, now it is shipped by batches. The smallest granular change is http2 framing: splitting a response or request into multiple framing fragments
[Improved] The minimum granularity has become a batch. After a batch of goods is produced, it can be transferred immediately. It is not necessary to wait for the entire order to be produced before transferring- Sign a transportation contract (three-way handshake)
- Place an order (first request)
- Place an order (second request)
- Simultaneous production of goods for the first order and the second order (server computing)
- Each batch of goods is produced, label the batch of goods to identify which order the goods are (framing)
- When a batch of goods is ready, it will be shipped, no need to care which order (transmission)
- Receiving and re-sorting which order the goods are (according to the frame identification corresponding to the response of that request)
- Each batch of goods is produced, label the batch of goods to identify which order the goods are (framing)
- When a batch of goods is ready, it will be shipped, no need to care which order (transmission)
- Receiving and re-sorting which order the goods are (according to the frame identification corresponding to the response of that request)
- until all shipments have been transferred
- Settle the account of the transportation contract once (waves four times)
Summarize
- It can be seen that the framing of tcp and the framing of http2 are different dimensions.
- The framing dimension of tcp is one shipment (one shipment per shipment), and the framing dimension of http2 is a batch of shipments (may be one shipment or several shipments)
- The essence of http2 framing is to split an original order (a request or response) into multiple batches (multiple frames) to reduce data granularity and increase flexibility
References
Why split the frame
In essence, as long as an order (response) is marked with an order (request) logo, which order can be identified, and the problem of first-order dependency can be solved (the latter order does not need to wait for the previous order to be transmitted), why? Need to break up orders into batches?
- The number of carts (TCP channel width, traffic width) is limited, breaking up does not speed up the transport process
- The purpose of splitting into batches (framing) is to support the distribution and transmission of data from the source. If an order has a large quantity and is shipped according to the order, it must wait for the production of the entire order to be completed before it can be transported. The granularity can be reduced by splitting into batches (framing), and one batch is transported when one batch is produced, and there is no need to wait for the production of the entire order to be completed.
How to understand that http1.1 is a text protocol and http2 is a binary protocol
- The corresponding discussion in stackoverflow is and corresponds to the domestic forum
Text protocol, the information transmission process goes through the following steps
- When writing text, because the rules are relatively loose, there may be extra spaces before and after, extra line breaks, etc.
- Transmission of text, the transmission is ASCII, that is, the encoding corresponding to the text
- Read text, understand text, identify words combined with ASCII codes, and then match meaning by string matching
binary protocol
- The binary here is mainly reflected in two aspects: "binary frame encapsulation" and "header compression"
"Binary frame encapsulation" is to break up the data and outsource a layer of binary frame data (used to identify the characteristics of the current frame)
- So this framing layer is binary encapsulated, not the content of http, so a more appropriate name should be "added binary framing layer"
- The binary frame data here uses binary as the granularity to represent the meaning of the data, and each 0 and 1 represents a special meaning
- The text protocol expresses meaning through the words corresponding to ASCII.
- That is to say, the granularity of the data is different. Originally there were several letters, but now it consists of several bits.
"Head Compression"
- The meaning is represented by the index value of the static table and dynamic table
- It is equivalent to a temporary secret code established by both parties
http2 header compression, how to synchronize the dynamic table of the browser and the dynamic table of the server
- [Question] Due to racing issues, another request was received before the request headers were not registered with the server.
- [Scheme] http2 has clear rules for framing, and no other framing can be inserted between the request header and the response header. This ensures that the complete request header and response header are transmitted in order. So there will be no racing problems.
- Corresponding discussion in stackoverflow
- The CONTINUATION frame in HTTP2 has related introduction , corresponds to the Chinese document
- Introduction to CONTINUATION frame in
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。