Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minimize UDP packet loss

I am receiving ~3000 UDP packets per second, each of them having a size of ~200bytes. I wrote a java application which listens to those UDP packets and just writes the data to a file. Then the server sends 15000 messages with previously specified rate. After writing to the file it contains only ~3500 messages. Using wireshark I confirmed that all 15000 messages were received by my network interface. After that I tried changing the buffer size of the socket (which was initially 8496bytes):

(java.net.MulticastSocket)socket.setReceiveBufferSize(32*1024);

That change increased the number of messages saved to ~8000. I kept increasing the buffer size up to 1MB. After that, number of messages saved reached ~14400. Increasing buffer size to larger values wouldn't increase the number of messages saved. I think I have reached the maximum allowed buffer size. Still, I need to capture all 15000 messages which were received by my network interface.

Any help would be appreciated. Thanks in advance.

like image 982
nath Avatar asked Nov 25 '11 09:11

nath


People also ask

Can UDP handle packet loss?

With User Datagram Protocol (UDP) traffic, there is no automatic transmission of lost packages. UDP is used in real time streaming applications which can deal with some amount of packet loss (or out of order reception). If an application requires UDP retransmission it must implement it on its own - or switch to TCP/IP.


1 Answers

Smells like a bug, most likely in your code. If the UDP packets are delivered over the network, they will be queued for delivery locally, as you've seen in Wireshark. Perhaps your program just isn't making timely progress on reading from its socket - is there a dedicated thread for this task?

You might be able to make some headway by detecting which packets are being lost by your program. If all the packets lost are early ones, perhaps the data is being sent before the program is waiting to receive them. If they're all later, perhaps it exits too soon. If they are at regular intervals there may be some trouble in your code which loops receiving packets. etc.

In any case you seem exceptionally anxious about lost packets. By design UDP is not a reliable transport. If the loss of these multicast packets is a problem for your system (rather than just a mystery that you'd like to solve for performance reasons) then the system design is wrong.

like image 158
tialaramex Avatar answered Sep 28 '22 16:09

tialaramex