Results 1 to 6 of 6

Thread: Multiple QNetworkRequest slows the GUI performance

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Multiple QNetworkRequest slows the GUI performance

    I have a single timer that will trigger the function findUpdate() every second in mainwindow. I have set an If condition, which will be set to 0 only when the reply is received. So is this efficient?
    No. Since you see your program gradually start to slow down, this probably means that server requests are backing up. More slowly than before, but your code is probably still making requests faster than they can be answered.

    And how can you have -one- flag that applies to -all- servers? If you set it to 0 when -any- reply is received from -any- server, what about all of the other servers who have not replied yet? If -any- server can set the flag to zero, then when your timer fires it will ask -all- of them for an update even if some have still not replied. Your findUpdate() rate will be set by the -fastest- server, not the slowest, and so requests to the slow servers will back up.

    Why are you so resistant to getting rid of the 1-second QTimer? It is the cause of the slowdown. Get rid of it. Your servers cannot all keep up with a 1-second request rate. If someone has specified that your program must update every second, you need to point out to them that this cannot be done.

    What you can do is to get rid of QTimers completely. In the algorithm I posted:

    - Ask the LED group for its data
    - Wait for the finished() signal
    - Get the data and tell the plot to update
    - Wait one second (for that LED group only)
    - Repeat

    Remove the "Wait one second" line and immediately ask the same LED group again for an update. If you do this for every LED group independently it means that your UI will receive updates at the fastest rate possible - as fast as each LED group is capable of responding. You cannot make it work any faster than this unless you make the servers faster.

    Your program should be completely asynchronous - you can't force each LED group to respond at the same rate, and should not try. The Qt way is to ask for something and let Qt tell when it is ready. If each LED group answers at a different rate, well that's just the reality of the situation and you can't force it to run faster. If you are on a bicycle, you aren't going to make it as fast as a car no matter how hard you pedal.

    Edit:


    If you still insist on using a QTimer in MainWindow, then you can make your findUpdate method work if you do this:

    - create a vector of flags, one entry in the vector for each server.
    - initialize the vector to zero for every entry

    In findUpdate():
    - look at the entries in the vector
    - for any zero entry, issue the get request to that server and set the flag for that server to 1

    In the finished() slot
    - when you receive the data for that server's request, set its flag to 0

    In findUpdate(), if any flags are set to zero, then you can issue a get request for those servers only. Any flags still set to 1 mean the request is still waiting, so you can't issue another one.

    This way, you can update the UI once per second with whatever new information has come in during the last second, but there will not be new information for every server. (And in the algorithm I posted above, you will also get rid of the "Repeat" line. Each server will now be under the control of findUpdate and will be asked for new data at most once per second. The slowest server will still be slow.)
    Last edited by d_stranz; 26th October 2020 at 19:35.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    deepikha (2nd November 2020)

Similar Threads

  1. Performance issues with multiple visible Windows
    By Zmote89 in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2017, 19:20
  2. Multiple QGLWidgets performance issue
    By louissmr in forum Qt Programming
    Replies: 0
    Last Post: 18th July 2013, 08:28
  3. Multiple QGLWidgets slow performance
    By seesomi in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2013, 09:20
  4. Replies: 1
    Last Post: 14th April 2011, 15:21
  5. rendering svg using QGraphicsSVGItem slows doen the performance
    By sanjayshelke in forum Qt Programming
    Replies: 4
    Last Post: 1st September 2009, 06:52

Tags for this Thread

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.