Allow limiting the number of concurrent processes #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Love this package. However, when testing it for speeding up some of our tooling, I noticed that with performance degraded quickly with a larger number of processes. This makes sense, since forking a process hundreds or thousands of times is an expensive operation.
The feature allows limiting that concurrency, so fewer concurrent processes are forked. This drastically reduces CPU usage, since it doesn't have to manage so many processes and sockets.
During my testing, running 1000 concurrent tasks (that simply returned
foo
), took ~20 seconds. Limiting it to 100 concurrent processes reduced that to 14 seconds.Possible Improvements
As implemented, it waits until all tasks of a concurrent group are completed before it starts the next group. It may be better to kick off a group, and as each task completes, start the next task until all are complete. However, this complicates things, and I am not convinced it would be any faster. Though, that is a gut feeling, not backed by any tests.
Open to suggestions.