-
Notifications
You must be signed in to change notification settings - Fork 501
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
Thread throttling #1167
base: main
Are you sure you want to change the base?
Thread throttling #1167
Conversation
I think it's going to be very hard to write robust code if Can you describe a bit more about your use case? Maybe we can find different approaches that will accomplish that. |
Thank you for your thoughts! And sorry for the late replay (I had to check with my mentor what I am allowed to write). My work is for an unpublished paper and I like to explore if dynamic resource management of the concurrent running threads makes sense for heterogeneous CPUs in terms of performance and/or energy efficiency gains. I want to first answer on your concerns regarding As I see it, the only information that is therefore missing, is how many threads rayon started with. Main Idea: Have an adjustable threadpool while running. Solutions:
As rayon spawns (as default) one thread for each OS provided thread on startup the second approach seemed promising. (Also, it was far easier to implement.) What can be accomplished with this solution: An example use case would be the changes of cgroups limitations.
** Additional thoughts:
Sorry for the wall of text. I hope it is somewhat understandable. |
I wonder if this is really necessary? If we just put the threads to sleep without making this observable by users of the thread pool, isn't this the same as if those threads were currently busy running other tasks? Meaning that So if those throttled threads would just not pull work from the global queue and go to sleep from the perspective of the OS, wouldn't that be enough for the heterogenous CPU use case? We would still need to ensure that |
I do think Rayon would benefit from adjusting current_num_threads, but maybe I am overseeing something. I am seeing a benefit from not adjusting it as well so I will try to outline my thoughts on both cases. As I understood rayon, it is not the same as those threads were currently busy running other tasks, because they never finish with running these tasks. If those threads are busy and another one isn't, it will steal tasks from the busy ones. I would assume, that this introduces some overhead. Of course, if the threads would be woken up at a later time, they would need to steal work from other queues. But my maybe naive thought would be, that we have more power available (that we can then use to perform steal(s)) after waking threads up than we have after sending them sleep. My thought was, that one can always call |
For one thing, Rayon thread pools are not bound to the available parallelism but can be constructed with a given fixed number of threads. |
Yes you are right. And the |
Yes, downstream code might have sized data structures using To be honest, I would prefer focusing on the throttling issue since
and postponing discussions on |
Would be okay for me. |
I have to implement something like a thread throttling approach.
Threads should be able to stop and start as needed (or, as my implementation suggest, can be set to sleep and wake up as needed from client libraries).
This could help f.e. for further developments regarding this issue: #319
Implementation details in which I don't know if I went the right way:
Latch
, a toggling latch for a global state in each thread.Registry
and I therefore made the Registry structpublic
.I would love to hear, if this is a feature rayon should support and if I got the implementation right.