Linux 如何对 UDP 协议进行拥塞控制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8683722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I do congestion control for a UDP protocol?
提问by Matt
I have a custom UDP protocol with multiple senders/receivers designed to send large files around as fast as possible. It is client/server based.
我有一个带有多个发送器/接收器的自定义 UDP 协议,旨在尽可能快地发送大文件。它是基于客户端/服务器的。
How can I detect congestion on the LAN to slow the rate of UDP packets being sent?
如何检测 LAN 上的拥塞以降低发送 UDP 数据包的速率?
EDIT: please, no comments on the use of UDP whether it's suitable or not. This protocol uses UDP but reassembles packets into whole files when they arrive.
编辑:请不要评论UDP的使用是否合适。该协议使用 UDP,但在数据包到达时将数据包重新组合成整个文件。
To rephrase the question: How do congestion control algorithms work and how is congestion detected?
重新表述这个问题:拥塞控制算法如何工作以及如何检测拥塞?
采纳答案by dail
This is assuming you have to use UDP (TCP would be preferred).
这是假设您必须使用 UDP(首选 TCP)。
From within the application, the only indication of network congestion is the loss of IP packets. Depending on how you have your protocol, you may want to do something like number each datagram going out, and if a receiver sees that it is missing some (or getting them out of order), send a message (or multiple) to the sender to indicate that there was loss of IP packets and to slow down.
在应用程序中,网络拥塞的唯一迹象是 IP 数据包的丢失。根据你的协议,你可能想要做一些事情,比如给每个发出的数据报编号,如果接收者发现它丢失了一些(或让它们乱序),向发送者发送一条(或多条)消息表示 IP 数据包丢失并减速。
There is a protocol called RTP(Real-time Transport Protocol) that is used in real time streaming applications.
有一种称为RTP(实时传输协议)的协议,用于实时流媒体应用程序。
RTP runs over UDP and RTCP(Real-time Transport Control Protocol) working with RTP provides measures for QoS(Quality of Service) like packet loss, delay, jitter, etc to report back to the sender so it knows when to slow down or change codecs.
RTP 运行在 UDP 和 RTCP(实时传输控制协议)上,与 RTP 一起工作,为 QoS(服务质量)提供措施,如数据包丢失、延迟、抖动等,以向发送方报告,以便它知道何时放慢或更改编解码器。
Not saying you can use RTP, but it may be helpful to look at to see how it works.
并不是说您可以使用 RTP,但查看它的工作原理可能会有所帮助。
回答by user1123450
Latency is a good way to detect congestion. If your latency starts going up, then you should probably slow down. A lost packet is the equivalent to latency = infinity. But you can never be sure if a packet was lost or is just very slow, so you should have a timeout to "detect" lost packets.
延迟是检测拥塞的好方法。如果您的延迟开始上升,那么您可能应该放慢速度。丢失的数据包相当于延迟 = 无穷大。但是您永远无法确定数据包是否丢失或速度非常慢,因此您应该有一个超时来“检测”丢失的数据包。
回答by Seth Noble
Flow control is an inherently difficult problem because all you really know is when you sent a packet and when you received a packet. Things like latency, loss, and even speed are all statistics that you have to calculate and interpret.
流量控制是一个固有的难题,因为您真正知道的是何时发送数据包以及何时接收数据包。延迟、丢失甚至速度等都是您必须计算和解释的统计数据。
The following article discusses these statistics and their meaning in depth: DEI Tech Note 0021: Loss, Latency, and Speed
以下文章深入讨论了这些统计数据及其含义: DEI 技术说明 0021:损失、延迟和速度
Finding a good solution has been the subject of much research and much commercial endeavor. Different algorithms (TCP, UDT, Multipurpose Transaction Protocol, etc.) use different methods and make different assumptions, all trying to figure out what is going on in the network based on the very sparse data available.
寻找一个好的解决方案一直是许多研究和商业努力的主题。不同的算法(TCP、UDT、多用途交易协议等)使用不同的方法并做出不同的假设,都试图根据非常稀疏的可用数据来弄清楚网络中发生了什么。
回答by Peter Jankuliak
It seems AIMDalgorithm is what they use in TCP and UDTprotocols to avoid congestion.
似乎AIMD算法是他们在 TCP 和UDT协议中用来避免拥塞的算法。
From the Wikipedia page:
从维基百科页面:
The additive-increase/multiplicative-decrease (AIMD) algorithm is a feedback control algorithm best known for its use in TCP Congestion Avoidance. AIMD combines linear growth of the congestion window with an exponential reduction when a congestion takes place. Multiple flows using AIMD congestion control will eventually converge to use equal amounts of a contended link.
加法增加/乘法减少 (AIMD) 算法是一种反馈控制算法,以其在 TCP 拥塞避免中的使用而闻名。AIMD 将拥塞窗口的线性增长与拥塞发生时的指数减少相结合。使用 AIMD 拥塞控制的多个流最终会收敛到使用等量的竞争链路。
回答by Tom
I had the following idea:
我有以下想法:
- Sender sends the data.
- Receiver waits a couple of seconds and then calculates the throughput rate / s
- Receiver sends the rate at which its receiving packets (bytes / s) to sender
- Sender calculates its rate of sending packets
- If the rate of sender is significantly higher, reduce it to match receiving rate.
- 发送方发送数据。
- 接收器等待几秒钟,然后计算吞吐率/秒
- 接收方发送其接收数据包的速率(字节/秒)给发送方
- Sender 计算其发送数据包的速率
- 如果发送方的速率明显较高,则将其降低以匹配接收速率。
Alternatively, a more advanced approach:
或者,一种更高级的方法:
- Sender starts sending at a predefined min rate (eg. 1kb / s)
- Receiver sends the calculated receiving rate back to sender.
- If the receiving rate is the same as sending rate (taking latency into account) increase the rate by a set pct (eg. rate * 2)
- Keep doing this until the sending rate becomes higher than receiving rate.
- Keep monitoring the rates to account for changes in bandwidth increase / reduce rate if needed.
- 发件人以预定义的最小速率(例如 1kb / s)开始发送
- 接收方将计算出的接收率发送回发送方。
- 如果接收速率与发送速率相同(考虑到延迟),将速率增加一个设定的百分比(例如速率 * 2)
- 继续这样做,直到发送速率变得高于接收速率。
- 如果需要,继续监控速率以考虑带宽增加/减少速率的变化。
Disclaimer: im not network expert, this might not work for you.
免责声明:我不是网络专家,这可能不适合您。