I am trying to put a hard limit in CPU usage for a dd command . I have created the following unit file
[Unit] Description=Virtual Distributed Ethernet [Service] ExecStart=/usr/bin/ddcommand CPUQuota=10% [Install] WantedBy=multi-user.target
which call the following simple script
#!/bin/sh dd if=/dev/zero of=/dev/null bs=1024k
As I have seen in this guide: http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html The CPU usage for my dd service should not exceed the 10%. But when I run the system-cgtop command the usage is about 70-75% .
Any ideas of what am I doing wrong and how can I fix it?
P.S. When I execute systemctl show dd
I get the following results regarding CPU
CPUShares=18446744073709551615 StartupCPUShares=18446744073709551615 CPUQuotaPerSecUSec=100ms LimitCPU=18446744073709551615
To run cpulimit as a background process, use the --background or -b switch, freeing up the terminal. To specify the number of CPU cores present on the system, use the --cpu or -c flag (this is normally detected automatically). Rather than limit a process's CPU usage, we can kill it with the --kill or -k option.
Description. systemd-run may be used to create and start a transient . service or . scope unit and run the specified COMMAND in it. It may also be used to create and start a transient .
systemd is a software suite that provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions; Its primary component is a "system and service manager"—an init system used to bootstrap user space and manage user processes.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With