UDP throughpout is very weak using Qt
-
Hey guys,
I try to send as much data as possible through my 100Mb ethernet interface. I expected to have a throughput around 90MBit/s.
My first attmept was to just send messages within a loop "to see what is acutally possible":void c_main::sendMessage() { baDatagram.append(getRandomString(1400)); QElapsedTimer elapsedTimer; elapsedTimer.start(); for(int iItr = 0; iItr < 1024; iItr++) { sUDPsocket->writeDatagram(baDatagram,QHostAddress("fd53::205"),920); } int iElapsedTime = elapsedTimer.elapsed(); qDebug() << "elapsed time:" << iElapsedTime; qDebug() << "throughput" << (1024 * baDatagram.size()) / (iElapsedTime / 1000)); }
The result is always an elapsed time around 34s and a throughput of around 42kB what is pretty far away from what is physically possible.
However, in my second attempt I tried to use a timer that sends a bundle of 8 messages every millisecond. This is what I should do anyway, since the loop blocks the rest of my programm. But still, the result is the same.Next, I used iperf to see if there is a difference.
Using iperf I get a throughput of almost 90MBit/s and I can transfer 221896 datagrams (maximal size of payload) in 30 seconds.So, the question is why iperf can transfer around 216 times more data in the same time than my code does? Any ideas?
Cheers!
-
Something odd with your system?
Tested:
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QUdpSocket sUDPsocket; QByteArray baDatagram(1400,'a'); QElapsedTimer elapsedTimer; elapsedTimer.start(); for(int iItr = 0; iItr < 1024; iItr++) { sUDPsocket.writeDatagram(baDatagram,QHostAddress("fd53::205"),920); } const int iElapsedTime = elapsedTimer.elapsed(); qDebug() << "elapsed time:" << iElapsedTime; qDebug() << "throughput" << (1024 * baDatagram.size()*1000) / (iElapsedTime); return 0; }
got
- 17ms and 84MBit/s in debug mode
- 13ms and 110MBit/s in release mode
Qt 5.8.0 Win7 32bit
-
Thanks for testing.
To be honest, I already thought about this as well but I don't have any clue where to look, especially because iperf obviously works fine. Any ideas where to look?
On the other hand I am now convinced that it isn't a serious problem in the code.Anyway, obviously you are connected via Gigabit-Ethernet. I wonder why you don't get more than 110MBit/s...
I am working on a banana pi (which doesn't have that much power as you have on your windows machine) with Qt 5.3.2.
-
@LeoC said in UDP throughpout is very weak using Qt:
Anyway, obviously you are connected via Gigabit-Ethernet. I wonder why you don't get more than 110MBit/s...
I guess @VRonin reaches 110 MByte/s (baDatagram.size() is in Byte), and that is effectively the limit for Gigabit Ethernet.
-
Start with using a profiler and measure what it's spending time with. Also, it looks like you aren't checking the return code of writeDatagram -- it could be returning some error code. Does it behave any different with an ipv4 address rather than ipv6?