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

Parallelism in metadata export with a Task Queue #41

Open
1 task
adrianq opened this issue Mar 22, 2019 · 0 comments
Open
1 task

Parallelism in metadata export with a Task Queue #41

adrianq opened this issue Mar 22, 2019 · 0 comments

Comments

@adrianq
Copy link
Member

adrianq commented Mar 22, 2019

  • Parallelize calls to groups and groups sets up to a max number

@tokland said:

There are some Promise.all(...) in the code, a general comment about it.

When we have limited/known number of requests in a Promise.all, it's ok. However, for size-unbounded requests, it can be dangerous, DHIS2 servers tend to reply with 500 when they get many parallel requests.

As you say in a comment, if we want efficiency, we will need a pool of promises (Bluebird provides one, with a {concurrency: N} option for Promise.map). A simple option is to use a sequential promise mapper. For example, I use this in our projects:

https://gist.github.com/tokland/71c483c89903da417d7062af009da571

Your code needs to be refactored a little bit to use the abstraction, you don't map async promises but the arguments (non-async) that will be used to create the promise. This is the only way, as when a promise is created, it starts doing work.

The good thing about using this abstraction is that whenever we want we can replace it for a concurrent implementation without changing the caller code, just the function in the utils file.

All this is a bit tricky, we can talk about it if you have any doubt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant