Sargis
Sargis

Reputation: 203

Optimal UDP datagram size

I have read a lot of related questions here, however its still quite confusing: how to choose the proper size for an UDP datagrams If the goal is to send data as fast as possible with an allowable packets loss about 5%?

I'm using Delphi 10.2 with Indy 10.

First I'm trying to detect PMTU by sending datagrams with DF flag:

UDPServer.Binding.SetSockOpt(IPPROTO_IP, IP_DONTFRAGMENT, 1)
SetLength(SData, N);
UDPServer.SendBuffer(ABinding.PeerIP, ABinding.PeerPort, SData);

In my particular test case the biggest N while data still arriving turns to be 1472, which, as I understand, means that this size datagrams are traveling non-fragmented.

Then I'm trying to send as much data as possible:

    TotalSent := 0;
    for L := 1 to 100 do begin
      for k := 1 to Count do begin
        SData[0] := k;
        UDPServer.SendBuffer(ABinding.PeerIP, ABinding.PeerPort, SData);
        TotalSent := TotalSent + N;
      end;
      If SLeepTm > 0 then sleep(SLeepTm);
    end;

Measuring total received data on client's side, I've found out that the best speed is achieved with a datagram size of 1464 bytes (contrary to the PMTU above has determined as 1472 bytes). The speed, or more accurately, data loss, with 1464 datagrams is about 2 times faster!

How do I determine this 1464 value in a real application without such a stress test, and am I correct in my reasoning that one should split data into datagrams of this size in an application for best efficiency?

Upvotes: 1

Views: 147

Answers (1)

nicolap8
nicolap8

Reputation: 1

There is an old question very similar to your: what-is-the-optimal-size-of-a-udp-packet-for-maximum-throughput whose answers are complete and informative.

Keep in mind that there can be important differences between a local network and the Internet.

Upvotes: 0

Related Questions