-
-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQUEST] Improve multi-threaded code #553
Comments
@nobounce For example on a server with multiple thousands running processes, it will take a long time to parse through So mostly the reason for having it on separate threads is to make sure the UI can respond to input (that don't require a new collection cycle) even if the collection is slow. However the current threading mess in btop can surely be improved. |
I can take on that challenge. I have a couple of PI's around to test it, maybe I get to write some tests that simulate heavy loaded systems. |
@aristocratos
|
@nobounce
You're most certainly welcome to try :)
The globals used are mostly for atomic signaling between threads and all are contained in the
This is because of how signal handling was initially setup. This can be avoided by setting a flag in the signal handler, returning to the thread where the signal was caught and then have a delayed response to the signal in the main thread.
There's no need to clean anything up really with the exception of making sure no threads are left running. The OS will take care of clean up.
You've got it turned around. You want to run the collection as late as possible before drawing to screen, otherwise you are not getting realtime data anymore. However, moving all "drawing to screen" to the main thread might be a good idea. But there will still be a need for either waiting for the collection cycle to finish or signal it to stop when changing options that inform how collection should be done. |
Runner
thread
@aristocratos |
Also can I assume #624 is going to be merged? I'll have overlapping code and I'm not looking forward to rebase this. So I would like start on that branch |
@nobounce #624 will be merged if it's stable on all platforms (when I have time to do testing). Many of your current pull requests are mostly 😉 good improvements/ideas, but they touch a lot code in a lot of different places (not helped by your automatic linting changing indentations, headers order and so on). The code in the other project was cleaned of warnings with the following clangd
So will be bringing that over at some point in the future also, for some added safety checks. |
I'm sorry, that's an ick, I can't help it 😆 I understand that the GPU thingy is on your list for 1.3 so you don't want to delay it further. If the header stuff is the only thing holding my PR's back I can omit them. |
I had a deeper look at the code in the last few weeks and came to the conclusion that the
Runner::_runner()
method is redundant.If I understand everything correctly, we execute the
Runner::run()
method. At the end, we signal theRunner
thread that there's work to do, so it starts executing.There is hardly any gain from executing this piece of code in a background thread. The work performed there does not take advantage of parallel execution because it has to wait for the main thread anyways. The current downsides are having lots of atomics and unreadable code.
Changing this will make the code much easier to understand because the control flow follows the execution, you don't have to guess what is happening in parallel and jump around.
I've already tested it and moved all the code from
Runner::_runner
in theRunner::run()
method and removed the thread and most of it's atomic booleans. There is no loss in performance (as I've said, the code gets executed in a serial fashion anyway).There are other areas which would benefit from parallel execution like polling for input and an multi-threaded signal handler.
The text was updated successfully, but these errors were encountered: