udpprocessing-efficiencypacket-loss

The most reliable and efficient udp packet size?


Would sending lots a small packets by UDP take more resources (cpu, compression by zlib, etc...). I read here that sending one big packet of ~65kBYTEs by UDP would probably fail so I'm thought that sending lots of smaller packets would succeed more often, but then comes the computational overhead of using more processing power (or at least thats what I'm assuming). The question is basically this; what is the best scenario for sending the maximum successful packets and keeping computation down to a minimum? Is there a specific size that works most of the time? I'm using Erlang for a server and Enet for the client (written in c++). Using Zlib compression also and I send the same packets to every client (broadcasting is the term I guess).


Solution

  • The maximum size of UDP payload that, most of the time, will not cause ip fragmentation is

    MTU size of the host handling the PDU (most of the case it will be 1500) -
    size of the IP header (20 bytes) -
    size of UDP header (8 bytes)
    
    1500 MTU - 20 IP hdr - 8 UDP hdr  = 1472 bytes
    

    @EJP talked about 534 bytes but I would fix it to 508. This is the number of bytes that FOR SURE will not cause fragmentation, because the minimum MTU size that an host can set is 576 and IP header max size can be 60 bytes (508 = 576 MTU - 60 IP - 8 UDP)

    By the way i'd try to go with 1472 bytes because 1500 is a standard-enough value.

    Use 1492 instead of 1500 for calculation if you're passing through a PPPoE connection.