On Thu, 2019-08-29,
tric...@accusoft.com wrote:
> Hi folks,
>
> I'm observing here packet loss over UDP transmissions, even if
> routed over the loopback device. Yes, of course, it is UDP, so it is
> understood that packets can be dropped. In this specific case,
> however, the receiver is just a dummy that does nothing more than
> call "recvfrom" in a tiny loop, and checks for the packet sequence
> number of the protocol. The sender is nothing but a tiny program
> that sends out packets in a loop, running into usleep every N
> packets to limit the bandwidth.
>
> Nevertheless, the receiver tells me that packets are
> missing. Naturally, the problem increases when the load of the
> system increases, i.e. if I start a couple of dummy programs that
> just occupy the CPU. Though this is a quite capable server...
>
> Unfortunately, TCP is not negotiable, this needs to be a UDP connection.
It seems to me this has to be about lack of flow control: the sender
is faster than the receiver, it doesn't care about the receiver, and
there's (with UDP) a fixed RX buffer. Staying on the loopback doesn't
change that.
You could change the protocol over UDP to include a flow control
mechanism, but then you might as well switch to TCP.
> I already reconfigured the kernel size buffers in /etc/sysctl.conf,
> but without much success. The problem remains.
Those buffers tend to be huge even in the default case, so it's mildly
surprising that they fill up, if your receiver is so fast. Note that
'netstat -uan' will show you how full the RX buffer is at any given
time.
> Is there any other interface that would allow me to receive packets
> more frequently, through the kernel buffer directly? Windows has
> this "RIO" (registered IO) interface which helped a lot -
> essentially, the application puts buffers aside and let the kernel
> fill them, instead requiring polling through recvfrom().
Don't know. Linux has recvmmsg(2) which lets you consume N UDP
messages in one call, instead of being awoken by poll/select N times
and calling read() N times.
Also, if you only need to read a sequence number at the start of the
message, you don't have to read all of it ... although I don't know
if that would help performance much.
> Is there something similar on Linux side that would minimize packet loss?
> Is there some other setting I should try?
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/
snipabacken.se> O o .