How to control how rayon par_iter splits work? #1134
-
I have a list of files I want to perform an expensive operation on (hashing them with sha256 and comparing to known good values). I have been using rayon However, when profiling I noticed a long tail of just a single thread doing work at the end. My files have very wildly varying sizes (from tens of bytes to hundreds of megabytes, I'm checking files installed by Linux distro package managers) so this makes sense: I thought I got unlucky and got a big file at the end. My first idea was to sort by size and put the big files first in the iterator that I run rayon on. Thus all the big slow jobs would get started early I thought. This did not work: one thread runs for an exceedingly long time instead. It appears that rayon splits the work in chunks and schedule those (and that if a chunk is long running, work can't be stolen from it). This makes sense to reduce the overhead of course, but I would like to adjust this behaviour somehow. Perhaps have smaller chunks, or associate a cost function with each entry in the iterator. Maybe let me provide a function where I manually chunk the work. I know ahead of time how costly each unit of work is (for large sizes it scales with the file size, which I already know from package metadata). So I could just take a fixed number of MB and declare that as a chunk. Or maybe you have another idea for how to deal with this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This would be a quick workaround, but it sounds like you do not really benefit from the work done by |
Beta Was this translation helpful? Give feedback.
This would be a quick workaround, but it sounds like you do not really benefit from the work done by
ParallelIterator
do as much as sequential as possible while keeping all cores occupied since every single work item is sufficiently large in your case. Hence maybe just usingpar_bridge
would immediately yield the maximum granularity best suited to this use case?