question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a pool size to QueryCursor#eachAsync

See original GitHub issue

I wrote a little wrapper that pretty much acts like QueryCursor#eachAsync(fn, [callback]) but with a small difference which basically allows it to have a pool of items available, enabling to exec faster and to make stuff in parallel.

Use case:

Each fn given to eachAsync is a promise that makes some IO and takes 5s to run. eachAsync would wait it to be finished before executing a new one but it doesn’t mean you cannot execute multiple at once and to always have a pool of X fn executing at the same time, which would enable a higher throughput.

Hence, if eachAsync could buffer the next Y items to not have to wait for a new IO between mongo and the Node app it would enable a higher throughput too.

API suggestion:

QueryCursor#eachAsync(fn, [options], [callback]) where options is something like:

{
    poolSize: >=1, // How many [fn] will be executed in parallel
    bufferSize: >=0 // How many items shall be retrieved in advance
}

If it has any interest I could think about making a PR for it.

Thanks for the good job guys!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
YouriTcommented, Jun 17, 2016

What about:

{
    simultaneous: >=1, // How many [fn] will be executed in parallel
    bufferSize: >=0 // How many items shall be retrieved in advance
}

You like both enhancements?

Will work on something in the upcoming days I believe.

0reactions
vkarpov15commented, Aug 5, 2016

Sure. In the meantime id recommend you just use co to implement this in your app, it should be a while loop with maybe 10 lines of code

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose v6.8.1: QueryCursor
A QueryCursor is a concurrency primitive for processing query results one document at a time. A QueryCursor fulfills the Node.js streams3 API, ...
Read more >
MongoDB in production: How connection pool size can ...
This article looks at what connection pool size is in MongoDB and how we can test the effect the pool size setting has...
Read more >
mongoose cursor batchSize - node.js - Stack Overflow
Try this: var myCursor = collection.find({}).cursor({batchSize:50}); myCursor.eachAsync((doc) => { ... }); Batch sizes are just for performance optimisation ...
Read more >
Mongodb cursor batch size example - Caritas Castellaneta
useMongooseAggCursor ] «Boolean» use experimental mongoose-specific aggregation cursor (for eachAsync() and other query cursor semantics) Returns: ...
Read more >
Cursors in Mongoose 4.5 | www.thecodebarbarian.com
With 4.5.0, we're introducing a new query method, .cursor() , that ... The point of eachAsync() is to make it easy to wait...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found