Results 1 to 6 of 6

Thread: UDP Performance bad

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default UDP Performance bad

    Hello,

    i've programmed a test-application in QT4-3-4 for Windows (Commercial eval for VS2003) to get maximum UDP-throghput.
    The application is a simple receiver, that gets UDP-datagrams and calculates throughput. We also have a sender (written in C, WinAPI) and several receivers (C, C#, Java...). Now we are testing QT's performance. With C, WSA, we got results of astonishing 900-950MBit/s.
    The QT-application has two threads, one for GUI and one only for receiving. I used QUdpSocket-class, but results were as bad as 35-40MBit/s.
    What is wrong it?? Has anyone same experiences??
    Here is how i did it (only the receiving function in the 2nd thread):
    Qt Code:
    1. void sTestThread::run()
    2. {
    3. quint32 dgs = 0;
    4.  
    5. started = true;
    6. initRecv();
    7. while ( started )
    8. {
    9. psock->waitForReadyRead( 20 );
    10. if ( psock->hasPendingDatagrams() )
    11. {
    12. fill = psock->pendingDatagramSize();
    13. psock->readDatagram( buffer, MAX_UDPSIZE, 0, 0 );
    14. dgs++;
    15. checkDg();
    16. }
    17. }
    18. deinitRecv();
    19. }
    To copy to clipboard, switch view to plain text mode 

    regards and thanks

    tigertap

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Performance bad

    The socket is owned by a wrong thread thus you are wasting time on thread synchronization. Instead create the socket in the run() method of the thread, it should get faster then. And don't use waitForReadyRead() - use signals and slots instead. You'll be able to get rid of the other thread then additionally speeding up your application (remember, threads slow down applications on single cpu systems and not make them faster).

  3. #3
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Performance bad

    Hello,

    The socket is created inside initRecv() (sorry, i did not tell) in the run(), so it should be in the right thread.
    Why not use waitForReadyRead()? Is it slow??

    thanks

    tigertap

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Performance bad

    Quote Originally Posted by tigertap View Post
    Why not use waitForReadyRead()? Is it slow??
    It increases the cpu usage and causes the thread to block, thus reducing the power of the whole system. If you don't block, you can handle a single socket in the main thread using signals and slots, this should increase performance of your program. I don't know if the change would be signification for you, but maybe it's worth to try...

  5. #5
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Performance bad

    Hmm, yes, I think I know what you mean.
    But the intention was to run the GUI-thread standalone from the receiving. This was part of the test-scenario. The tests are running on multicore-machines, hopefully QT distributes them on the processors. (with WinAPI, i know there is a function called SetProcessorAffinity() or something like that).
    What makes me wonder, is the huge difference between the C WinAPI, C# and C with QT in throughputs. The receiver applications are all done in the same way, one thread for GUI, one only for receive. C, C# allow 900-950MBit/s with moderate loss, Java is slightly more worse, but C with QT.

    One thing that I can't set in QUdpSocket is the buffer size. At the moment I'm trying to program the app in QT3, to set the buffer size. For 1GBit/s it should be 2.5MB to have enough space to collect datagrams in one Windows-slice of 20ms. I think that the problem is lying somewhere in here.

    regards
    tigertap

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Performance bad

    Quote Originally Posted by tigertap View Post
    But the intention was to run the GUI-thread standalone from the receiving.
    I understand. Nevertheless you have a busy waiting loop that is completely redundant.

    The tests are running on multicore-machines, hopefully QT distributes them on the processors. (with WinAPI, i know there is a function called SetProcessorAffinity() or something like that).
    Qt has nothing to do with that. It assumes the operating system "knows better", so threads might be scheduled to the same processing unit. You should be able to verify that using system monitoring tools.

    What makes me wonder, is the huge difference between the C WinAPI, C# and C with QT in throughputs. The receiver applications are all done in the same way, one thread for GUI, one only for receive. C, C# allow 900-950MBit/s with moderate loss, Java is slightly more worse, but C with QT.
    You may use a profiler to find the bottleneck. Seems that you are not reading data fast enough, but why - that I don't know.

Similar Threads

  1. Performance problems with overlapping qgraphicsitems
    By brjames in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 21:42
  2. QAbstractProxyModel::mapToSource performance issues
    By maximAL in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 22:48
  3. Replies: 1
    Last Post: 4th October 2006, 16:05
  4. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  5. Increasing performance from Qtextedit, listview, etc?
    By taylor34 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.