Use jobserver in wasm-builder to limit concurrency of spawned cargo processes #4946
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.
When building multiple runtimes in parallel, each of them will try to use the concurrency set by the parent cargo process. For example, in a system with 8 cpu cores, building 3 runtimes in parallel creates 8 * 3 tasks. This results in the system hanging because of the high cpu and memory usage.
This PR allows the substrate_wasm_builder to use the same jobserver as the parent cargo process, making all invocations of cargo share the same concurrency pool. So in a system with 8 cores, there will never be more than 8 tasks running at the same time.
Implementation roughly based on cargo but with less unsafe.
This can be tested by telling cargo to use half the cpu cores, like
cargo build -j4
in an 8 core machine. Before this PR it will use 100% cpu when building 2 runtimes in parallel, after this PR it will always use 50%.