Avoid cargo throttling system with too many tasks on slower CPUs #8556
Labels
A-jobserver
Area: jobserver, concurrency, parallelism
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Performance
Gotta go fast!
Describe the problem you are trying to solve
I develop on a Pinebook Pro. Sometimes, builds on cargo can seriously freeze up my computer because it diligently spawns as many parallel jobs as it can even though this may not be desired. I have a few ideas for solutions to this, but figured I'd at least start the discussion as I think this is a reasonable thing to consider.
Right now, the number of compilation tasks is determined purely by the number of cores available on the CPU. It would be nice if this were altered in some cases to avoid completely throttling the system, potentially with an easy setting. While it is possible to configure the number of concurrent jobs with build.jobs, this is not always ideal as the number of jobs depends on system load and may also not be as easy for a user to determine.
Describe the solution you'd like
Option 1: Cargo could occasionally check the system load (either CPU percentage or load average) during compilation and scale down the number of jobs if the system load reaches a certain threshold. This can also safeguard against concurrent cargo compilations by ensuring that two cargo instances don't spawn twice the number of threads that can be safely handled.
Option 2: Potentially, cargo could keep track of a global lock on the number of jobs running running, and use that when determining the number of jobs to schedule per instance.
Option 3: Similarly to option 1, cargo could also alter the scheduling priority of individual tasks to ensure that other applications don't grind to a halt.
Notes
The solutions here may not always be platform-independent. For example, I know that Linux (and other *nix varieties) offer way more tools for determining system load than Windows, and it may be that we can't do something reasonable on every platform.
Right now, the workaround for this is to manually set build.jobs and/or set the scheduler priority of cargo on the command-line. It would be nice to have more built-in support for this, though.
This problem is also not unique to cargo, although it is somewhat unique as cargo is designed to multithread as much as possible whereas traditionally compilers were spawned in parallel by IDEs or makefiles.
The text was updated successfully, but these errors were encountered: