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.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?
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.)
Bookmarks