Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do congestion control for a UDP protocol?

Tags:

c

linux

udp

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.

How can I detect congestion on the LAN to slow the rate of UDP packets being sent?

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.

To rephrase the question: How do congestion control algorithms work and how is congestion detected?

like image 717
hookenz Avatar asked Dec 30 '11 20:12

hookenz


3 Answers

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.

like image 138
user1123450 Avatar answered Sep 19 '22 13:09

user1123450


This is assuming you have to use UDP (TCP would be preferred).

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.

There is a protocol called RTP (Real-time Transport Protocol) that is used in real time streaming applications.

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.

Not saying you can use RTP, but it may be helpful to look at to see how it works.

like image 20
dail Avatar answered Sep 20 '22 13:09

dail


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

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.

like image 21
Seth Noble Avatar answered Sep 20 '22 13:09

Seth Noble