Use of CPUQuota in systemd

Alternate ways to limit cpu usage: 1. Use taskset command. 2. Use control groups. 3. Use docker and limit cpu utilization by using cpuset. 4. Reduce the number of threads in the application. Some calculation is required with this approach.


Another thing you could try is run cpulimit as a daemon. I have not tested this; it's just an idea.

It's in the ubuntu repos:

sudo apt install cpulimit

Use systemd if you like. This should limit all instances of dd to 20% CPU.

[Unit]
Description=dd CPU Limiter

[Service]
ExecStart=/usr/bin/cpulimit -e dd -l 20

[Install]
WantedBy=multi-user.target

source


I accidentally ran across another valid answer given on https://unix.stackexchange.com/questions/213903/linux-cgroups-limit-cpu-usage-in-absolute-values-which-do-not-depend-on-cpu-spe

If you want a hard limit on CPU bandwidth, you can use cpu.cfs_quota_us and cpu.cfs_period_us. From the Kernel's CFS docs:

The bandwidth allowed for a group is specified using a quota and period. Within each given "period" (microseconds), a group is allowed to consume only up to "quota" microseconds of CPU time. When the CPU bandwidth consumption of a group exceeds this limit (for that period), the tasks belonging to its hierarchy will be throttled and are not allowed to run again until the next period.