user3120127
user3120127

Reputation: 29

QUdpSocket reads - occasionally missing datagrams observed with tcpdump

I have a relatively simple, server-to-many client setup. The server is sending out datagrams using multicast, and the (potentially many) clients receive them.

The Linux (RHEL) clients are receiving/reading an approximately 3-4 Mbps stream of these datagrams, using:

    QByteArray datagram;
    while (udpSocketReceiver->hasPendingDatagrams())
    {
        datagram.resize(udpSocketReceiver->pendingDatagramSize());
        udpSocketReceiver->readDatagram(datagram.data(), datagram.size());
    }

This seems to work probably 99.99% of the time. However, I am occasionally seeing that a datagram gets missed (as observed by internal counters/schema that I'm using). My first thought was "well, it's UDP - it must just be getting dropped in transmission."

However, I'm also monitoring the client/receiver side using tcpdump ... and I'm also seeing the "missing" datagrams present there, that are missed by the application. It would seem that the missed datagrams are being received by the network interface just fine, but I'm occasionally dropping them coming into the application layer. Just about the last place I'd expect to be dropping them.

I've been playing around with adjusting applicable buffers in Linux (net.core.rmem_max, net.core.rmem_default), but without any luck.

Thanks for any help.

Upvotes: 0

Views: 302

Answers (1)

Mohammad Kanan
Mohammad Kanan

Reputation: 4582

This is normal behavior! even if you see a UDP packet arrives to your computer physical layer, it does not mean that the application has for sure to receive it .. due to buffering limits .., or CPU, memory bottleneck.

UDP packets are dropped in three possible transmission slots:

Sender Buffer On every UDP socket, there’s a send buffer that queues packets. The system fetches and sends packets out as quickly as possible, But if you have a network interface that’s slow or getting time slot not enough to handle the queue 100% effectively, it’s possible that it will not be able to send the packets as fast as you put them in! in this case some packets are simply discarded. More reading.

Network Lost packets

Even if sender successfully transmits a UDP packet in the (public) network, it still might get lost along the way. Why: routing algorithms are complex .. everything in the way works also on buffer basis as well as priority basis .. on top of that network is not 100% reliable .. packet data might be dropped due to checksum errors ...etc.

Receiver buffer a UDP packet might arrive at receiver physical layer. But the application listening and waiting for a packet with a socket receive buffer. the size of that buffer can cause drop? if the application can't handle all buffers at the rate they are queued, the buffer can overflow and packets awe discarded Further reading this can help how to set receiver buffer.

Upvotes: 0

Related Questions