-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
@lerna/run with just-in-time queue management #2045
@lerna/run with just-in-time queue management #2045
Conversation
@evocateur Please let me know if you have any questions or concerns about the PR. I'm also happy to discuss the implementation if you think it could be better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really excited about this, thanks for your patience!
I'm so excited to use |
I wasn't aware of some of these improvements! This looks really good. Any eta? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for your patience!
As for ETA on |
Is it possible that somehow we broke |
This PR introduces just-in-time (JIT) queue management when running scripts in parallel in @lerna/run. The current model for running scripts in parallel uses batches which are causing inefficiencies as threads have to wait for a batch to finish before they can pick up new tasks.
We currently have 84 packages in our monorepo. Below is a visualization of what running scripts in parallel using batches look like:

In contrast, here is a visualization of running scripts with JIT queue management:

The total build time is reduced by half!
Description
We create a graph representation of the packages to be built and an empty promise queue (p-queue). We find every leaf-node from the graph and them to the promise queue with a post-run-task that will prune the graph of references to self and then attempt to add new leaf-nodes to the promise queue. Finally, cyclical packages, if any, are added to the promise queue.
Picking leaf-nodes, pruning the graph and adding cyclical packages last are all existing patterns used in Lerna. This PR simply performs some of these operations dynamically and on a JIT basis.
Motivation and Context
As illustrated by the graphs above, allowing each thread to pick an available package instead of having to wait for a batch to finish optimizes concurrency.
How Has This Been Tested?
There are many existing tests in Lerna for running scripts in parallel. All tests are green. In addition, we have been using a fork of Lerna with JIT queue management in our repo with developers, CI, and CD running it daily for about a month.
Types of changes
Checklist: