Skip to content
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

Limited parallelism #1

Open
ArtemGr opened this issue Nov 15, 2016 · 0 comments
Open

Limited parallelism #1

ArtemGr opened this issue Nov 15, 2016 · 0 comments

Comments

@ArtemGr
Copy link
Owner

ArtemGr commented Nov 15, 2016

When handling two-level hierarchies, it's often useful to limit parallelism.

Here's what I often do, in pseudocode:

level1 = ids.map (|id| ctx.read (id)) .collect()  // Load the first level in parallel.
for (idx in level1) {
  level2 = idx.map (|id| ctx.read (id)) .collect()  // Load the second level in parallel.
  ...
}

Now, I don't need the entirety of the first level loaded when I'm handling the second level. In fact, loading the first level might be seen as inefficient in terms of memory use and ordering of the AIO operations. What I need is prefetching some (maybe just a single entry) of the first level in parallel while focusing on the second level.

I wonder what the proper/best API for this might look like.

P.S. There seems to be some explicit parallelism adaptors already. On one hand, join_all, which runs all futures in parallel, on another hand, buffer_unordered, which runs a fixed chunk of the futures in parallel. We need something in between, an adapter that eventually runs all the futures, but not more than a couple of them at a time.

P.S. Another use case, in pseudocode:

let oids = [...];
let stats = parallelize (99, oid.map (ctx.stat (oid)));
for bytes in parallelize (9, stats.map (ctx.read (oid, size))) {...}

We often have a collection that we want to generate futures from, but we don't want to generate all the futures immediately (that makes the app pause and eats RAM), so there needs to be some kind of a buffer that applies a map in advance but only for a limited number of entries. This seems to be entirely generic, e.g. we take a simple Iterator and produce a different Iterator that buffers a fixed number of entries, that's all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant