0

During cargo run, rustc by default takes up all CPU resources. Is it possible to limit CPU usage? For example, cpulimit -l 40 works for cargo, but rustc processes still use 100% of the CPU.

  1. Fedora release 40 (Forty): 6.9.7-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC
  2. rustc 1.79.0 (129f3b996 2024-06-10)
  3. cargo 1.79.0 (ffa9cf99a 2024-06-03)
  4. stable-x86_64-unknown-linux-gnu unchanged -rustc 1.79.0 (129f3b996 2024-06-10)

UPD: cargo build -j x or CARGO_BUILD_JOBS=x this helped.

10
  • 2
    you've not mentioned the OS you are working with,the hardware etc - ie its too vague. take a look at taskset (linux) and see if that helps. If a program takes 100% its typically because there's 100% available ...
    – ticktalk
    Commented Jul 10 at 8:32
  • 1
    @ArtemBaranov can you try cpulimit -m -l 40?
    – Dogbert
    Commented Jul 10 at 8:39
  • 3
    do you want something like cargo build -j x or CARGO_BUILD_JOBS=x?
    – hellow
    Commented Jul 10 at 9:39
  • 1
    Something like systemd-run --scope --user --property CPUQuota=50% cargo run maybe?
    – Jmb
    Commented Jul 10 at 9:39
  • 1
    You can also look at reducing the codegen-units to directly target rustc
    – chesedo
    Commented Jul 10 at 10:52

0

Browse other questions tagged or ask your own question.