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

Introduce 'nice' value under cargo.toml -> [build] #9250

Open
ShadowJonathan opened this issue Mar 10, 2021 · 8 comments
Open

Introduce 'nice' value under cargo.toml -> [build] #9250

ShadowJonathan opened this issue Mar 10, 2021 · 8 comments
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! S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@ShadowJonathan
Copy link

Describe the problem you are trying to solve

Often enough I have cargo builds running in the background, and then I open up some entertainment while it finishes, but I often notice that my desktop is generally slow (no surprise, something is hammering the CPU in the background). I've began doing nice -n 20 bash -c "cargo build" (or something similar) recently, however, I still sometimes forget it and get frustrated to cancel the build and restart it with the (pretty verbose) nice prefix.

Describe the solution you'd like

Add a string/int nice config parameter to cargo.toml, under [build].

If int: An absolute value cargo has to attempt to set the nice value to on compilation threads/processes.

If string: A "relative" value (-2, +5) to try to set to on compilation threads/processes.

This setting is ignored on targets which don't support nice-esc prioritisation (windows comes to mind), though maybe a generic priority config value could be introduced which attempts to do this across many operating systems.

If the nice value is less than the current value, and the current running-as user has no privilege to bump down the nice value, then it could/should be ignored with a warning printed to stderr or stdout.

@ShadowJonathan ShadowJonathan added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 10, 2021
@Eh2406
Copy link
Contributor

Eh2406 commented Mar 10, 2021

cc #9221

@ShadowJonathan
Copy link
Author

(i should note that jobs != absolute CPU usage, because of kernel scheduling and multi-threaded compilation and such, nice in this case then actually allows a good prioritization configuration value)

@ehuss ehuss added the Performance Gotta go fast! label Mar 10, 2021
@pgray
Copy link

pgray commented Jun 30, 2023

i'm looking for this exact functionality

i've tried aliases and bash functions but i think cargo supporting it directly would be... nice 😄

i'm surprised more build tools haven't added support as it results in a much more responsive experience in browsers/apps/etc. while compiling

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. A-jobserver Area: jobserver, concurrency, parallelism labels Jul 1, 2023
@the8472
Copy link
Member

the8472 commented Nov 4, 2023

You could also try schedtool -B -e cargo <args> or schedtool -I -e cargo <args> for the BATCH and IDLE scheduling policies, depending on how much you want them deprioritized.

@soloturn
Copy link
Contributor

soloturn commented Dec 30, 2023

pgray, "nice" is not part of a build tool, but outside. if you want nice experience, use "nice cargo ...". build tool does not need this complexity. in windoes this is not caled nice, but start /low or so. again nothing to do with cargo.

a way to go might be to control number of jobs, as suggested in #12912. but personally i am fan of using nice - as long it does not cause out of memory killer to terminate my browser for example.

@melvyn2
Copy link

melvyn2 commented Dec 30, 2023

IMO this would be more fitting for .cargo/config.toml, rather than a crate's manifest - this build option doesn't really have anything to do with a specific crate.
Also, limit job count/CPU usage doesn't fulfill the same use-case, as it doesn't adapt to other system loads. With a low priority, jobs can still use 100% CPU if no other processes need it, while dropping as low as needed when the user is doing something else mildly intensive.

@weihanglo
Copy link
Member

FWIW, OOM killed issue is tracked in #9157, as there might be other specific approaches for it.

@pcgeek86
Copy link

This is really important for lower-end systems that can get completely hung installing basic software.

Case in point:

I just spun up an e2-micro virtual machine in Google Cloud Platform (GCP). I installed the Rust toolchain on it. Then I tried to install stu with cargo install stu, which is an S3 storage Terminal UI (TUI) application. The VM eventually completely hung, and I lost my SSH session to it, because it's compiling dependencies.

If Cargo were running as a lower priority Linux process, I probably would not lose connectivity to my remote servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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! S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

9 participants