-
Notifications
You must be signed in to change notification settings - Fork 506
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
Nested install() has counter-intuitive behavior #872
Comments
Ah crap, could it be #765? |
I think you're missing what happens to the caller while it waits for the installed task to complete in the other pool. If you call
Yeah, pretty much. |
Thanks, are you saying that this use-case cannot currently be expressed nicely in rayon and I need to wait for a new primitive/API to be introduced? |
I think something like the "critical section" idea would make this pretty nice and easy, but there are probably ways you can hack around that in your own code. For example, you could use a |
I see, will have a try. Closing as this is virtually a duplicate of ongoing work/discussions. |
Hello,
Please refer to this Playground link.
My main goal here is to split rayon's workload in two categories:
heavy
work, which in real life brings up heavy resources and should have limited concurrency, say 2 concurrent workers.cheap
work, represented by asleep
in my Playground. This should run with high concurrency (I've hardcoded thread count to 12 just to illustrate the issue).Thing is, each heavy work item depends on calling many cheap work items. In my example I need to process 10 heavy items, each spawning 1000 cheap items.
Since it seems like rayon has no API to limit worker count per
par_iter
invocation (#826 maybe), I've instead tried to create a pool for heavy work, a pool for cheap work, and nesting them through the use ofpool.install
which according to docs, makespar_iter
use that pool.The code prints a millisecond timestamp so we can easily debug how many items are worked on in parallel.
What I thought the code would do
Show lines with similar timestamps in batches of 2, since I've limited to 2 threads, and each takes roughly the same amount of time (1000 short sleeps spread across 12 threads):
What the code actually does
9 heavy work items are immediately scheduled concurrently (even though they're inside a 2-thread pool install), then all the 9000
sleep
go to work, then the last work item starts (1000 sleeps), then the program finishes.It's as if the outer (heavy)
par_iter
pool somehow gets taken over by the nested (cheap)par_iter
pool and therefore schedules the heavy work on it.Am I misunderstanding the
install
API? What should I do differently? Is that a bug in rayon?Thanks for your help!
The text was updated successfully, but these errors were encountered: