In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about how to deal with the problem of tcp sticky bags, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
The methods to deal with the tcp sticky packet problem are as follows: (1) fixed-length transmission method, in which the sender subpackets with LEN as the length when sending data; (2) tail marking sequence method, which sets a special byte sequence at the tail of each packet to be sent; (3) header marking step-by-step receiving method, which defines a user header and indicates the size of each packet sent in the header.
The method to deal with the sticky package problem of tcp:
1. Design plan 1: send with fixed length
The design of fixed length is adopted when sending data, that is, no matter how many big data sends, the packet is divided into fixed length (for ease of description, the fixed length is marked as LEN here), that is, the sender uses LEN as the length to subpackage when sending data. In this way, the receiver receives with a fixed LEN, so that the sending and receiving can correspond one to one. When subcontracting, it may not be able to be completely divided into multiple complete LEN packages, the last package will generally be smaller than LEN, when the last package can fill the insufficient part of the blank bytes.
Of course, this approach has its drawbacks.
1. The insufficient length of the last package is filled with blank, that is, invalid byte order. Then it may be difficult for the receiver to identify the invalid part, which itself is to make up the position and has no practical meaning. This brings trouble for the receiver to deal with its meaning. Of course, there is also a solution, which can be made up by adding flag bits, that is, adding a fixed-length header at the front of each packet, and then sending the end tag of the packet together. The receiver confirms the invalid byte sequence according to this tag, thus realizing the complete reception of the data.
two。 In the case of random distribution of packet length, it will cause a waste of bandwidth. For example, if the sending length may be 1pm, 100pm, 1000pm, 4000 bytes, etc., it needs to be sent according to the maximum fixed length of 4000, and other packets with packets less than 4000 bytes will also be filled to 4000, resulting in an invalid waste of network load.
To sum up, this scheme has a good effect when the packet length is stable (tends to a fixed value).
2. Design scheme 2: tail marker sequence
A special byte sequence is set at the end of each packet to be sent, which has a special meaning and has the same meaning as the Terminator "\ 0" of the string, which is used to mark the end of the data packet. The receiver can analyze the received data and confirm the boundary of the packet through the tail sequence.
The shortcomings of this method are obvious:
1. The receiver needs to analyze the data and identify the tail sequence.
two。 The determination of the tail sequence is a problem in itself. What kind of sequence can be used as a Terminator like "\ 0"? This sequence must be a meaningful data sequence that does not normally have any human or program recognizable data, just as "\ 0" is an invalid string content and can therefore be used as the end tag of a string. What is this sequence in ordinary network communication? I think it's hard to find the right answer for a while.
3. Design scheme 3: receiving the header tag step by step
The implementation of this method is that a user header is defined and the size of each packet sent is indicated in the header. Each time the receiver reads the data with the size of the header, it is bound to read the data of only one header, get the data size of the packet from the header, and then read it again according to this size, and then read the contents of the data.
In this way, a header is encapsulated when each packet is sent, and then the receiver receives a packet twice, the first time, and the second time according to the size of the header. The essence of data [0] here is a pointer to the body of the data or the starting position of a contiguous data region. So it can be designed as data [user _ size], in that case. )
The following is a picture to show the design idea.
As can be seen from the figure, the data is sent with the action of encapsulating the header; the receiver splits the reception of each packet into two.
This scheme seems exquisite, but in fact it is also flawed:
1. Although the header is small, each packet needs to encapsulate more sizeof (_ data_head) data, and the accumulation effect can not be completely ignored.
two。 The receiving action of the receiver is divided into two times, that is, the data reading operation is doubled, and the recv or read of the data reading operation are system calls, which is an impact on the kernel that cannot be completely ignored, and the performance impact on the program is negligible (the speed of system calls is very fast).
Advantages: avoid the complexity of program design, its effectiveness is easy to verify, and it is easier to meet the stability requirements of software design. To sum up, plan three is the best policy!
After reading the above, do you have any further understanding of how to deal with the problem of tcp sticky package? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.