当前位置:网站首页>TCP packet sticking problem
TCP packet sticking problem
2022-07-06 17:53:00 【TABE_】
Here's the catalog title
TCP Stick package problem
TCP Sticky packet means that the data of several packets sent by the sender arrive at the receiver and become a packet , From the receive buffer , The head of the next packet of data is next to the tail of the previous one , There are many reasons for sticking , It could be from the sender , It could be from the receiver .
cause TCP The reason for sticking the bag
Sender reason
The sending end sends multiple packets to the receiving end , More efficient sending to the receiver , So the optimization algorithm is used (Nagle Algorithm ), Will be multiple with smaller intervals 、 Data with a small amount of data , Merge into a large block of data , Then the packet is sealed .
TCP By default Nagle Algorithm ( The main role : Reduce the number of newspaper segments in the network ), and Nagle Algorithms do two things :
- Only the last group is confirmed , Will send the next packet
- Collect multiple subgroups , Send together when a confirmation arrives
Nagle The algorithm may cause packet sticking problem on the sender .
The receiver's reason
TCP When a packet is received , It will not be handed over to the application layer immediately for processing , In other words, the application layer does not immediately process . actually ,TCP Save the received packet in the receiving cache , The application then actively reads the received packets from the cache . thus , If TCP The speed of receiving packets to the cache is faster than that of applications reading packets from the cache , Multiple packages will be cached , It is possible for an application to read multiple packages that are glued together .
How to deal with it TCP Sticky package
If multiple groups of data sent by the sender are originally different parts of the same piece of data , For example, a file is divided into multiple parts and sent , At this time, of course, there is no need to deal with the sticking phenomenon . If multiple packets are irrelevant , Even juxtaposition , Then we must deal with the sticking phenomenon at this time
The sender
For the packet sticking problem caused by the sender , Can be closed by Nagle Algorithm to solve , Use TCP_NODELAY Option to turn off the algorithm .
The receiving party
The receiver has no way to deal with packet sticking , Only the application layer can handle the problem .
application layer
The solution of application layer is simple and feasible , It can not only solve the sticking problem of the receiver , It can also solve the packet sticking problem of the sender .
terms of settlement : Loop processing , When an application reads a packet from the receive cache , After reading a piece of data , You should cycle through the next piece of data , Until all the data is processed , But how to judge the length of each data ?
- Format data : Each data has a fixed format ( Start Rune , Terminator ), This method is simple and easy , However, when selecting the start and end characters, make sure that the beginning and ending characters are not included inside each data .
- Sending length : When sending each piece of data , Send the length of the data together , For example, before prescribing data 4 Bits are the length of the data , The application layer can judge the start and end position of each group according to its length .
Why? UDP No sticking problem
TCP In order to ensure reliable transmission and reduce additional overhead ( Every time the contract is awarded, it has to be verified ), Stream based transmission is adopted , Stream based transport does not consider messages to be one by one , Is unprotected message boundary ( Protect message boundaries : Transmission protocol refers to the transmission of data on the Internet as an independent message , The receiver can only accept one independent message at a time ).
UDP Is message transmission oriented , There are protected message boundaries , The receiving party accepts only one piece of information at a time , So there is no sticking problem .
for instance : There are three packets , The sizes are 2k、4k、6k, If the UDP Send it , No matter how big the receiver's receive cache is , We must send at least three times before we can send the data packet , But use TCP If the agreement is sent , We only need the receiver's receive cache to have 12k Size , You can put this... At one time 3 All packets have been sent .
边栏推荐
- Example of batch update statement combining update and inner join in SQL Server
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
- SQL statement optimization, order by desc speed optimization
- Single responsibility principle
- 历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
- Debug xv6
- 【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- BearPi-HM_ Nano development environment
- 微信小程序获取手机号
猜你喜欢
Optimization of middle alignment of loading style of device player in easycvr electronic map
EasyCVR授权到期页面无法登录,该如何解决?
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
SQL statement optimization, order by desc speed optimization
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
PyTorch 提取中间层特征?
Appium automated test scroll and drag_ and_ Drop slides according to element position
RepPoints:可形变卷积的进阶
随机推荐
传统家装有落差,VR全景家装让你体验新房落成效果
The NTFS format converter (convert.exe) is missing from the current system
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
Kali2021 installation and basic configuration
C# NanoFramework 点灯和按键 之 ESP32
Binary search strategy
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
Spark accumulator and broadcast variables and beginners of sparksql
Easy introduction to SQL (1): addition, deletion, modification and simple query
Unity小技巧 - 绘制瞄准准心
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Interview assault 63: how to remove duplication in MySQL?
The art of Engineering (3): do not rely on each other between functions of code robustness
远程代码执行渗透测试——B模块测试
【ASM】字节码操作 ClassWriter 类介绍与使用
MySQL error reporting solution
sql语句优化,order by desc速度优化
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]