What is the optimal size of a UDP packet for maximum throughput?
c++, linux, network-programming, udp, windows
Solution
The best way to find the ideal datagram size is to do exactly what TCP itself does to find the ideal packet size: Path MTU discovery.
TCP also has a widely used option where both sides tell the other what their MSS (basically, MTU minus headers) is.
Problem
I need to send packets from one host to another over a potentially lossy network. In order to minimize packet latency, I'm not considering TCP/IP. But, I wish to maximize the throughput uisng UDP. What should be the optimal size of UDP packet to use? Here are some of my considerations: The MTU size of the switches in the network is 1500. If I use a large packet, for example 8192, this will cause fragmentation. Loss of one fragment will result in the loss of the entire packet, right? If I use smaller packets, I'll incur the overhead of the UDP and IP header If I use a really large packet, what is the largest that I can use? I read that the largest datagram size is 65507. What is the buffer size I should use to allow me to send such sizes? Would that help to bump up my throughput? What are the typical maximum datagram size supported by the common OSes (eg. Windows, Linux, etc.)? Updated: Some of the receivers of the data are embedded systems for which TCP/IP stack is not implemented. I know that this place is filled with people who are very adament about using what's available. But I hope to have better answers than just focusing on MTU alone.