Skip to main content
added 105 characters in body
Source Link
Martian2020
  • 1.5k
  • 2
  • 12
  • 33

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000
sudo cgset -r cpu.max="200000 100000" mygroup1 
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

User cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage (this syntax changes 1st value only):
sudo cgset -r cpu.max=100000 mygroup1

Notes for cgroups:

cpu.max has two values: the first value is the allowed time quota in microseconds for which all processes collectively in a child group can run during one period. The second value specifies the length of the period. For multicore/multiprocessor systems 1st is quota for all cores, 2nd is for one, so setting 1st two times greater than 2nd is expected to result in CPU usage of 2 divided by total number of cores.

On my system min valid value is 1000, max is 1000000.

Using second value of 100000 (default) resulted in additional 2x-3x speed penalty when I run ffmpeg, using 1000000 resulted in no noticable penalty.

Surprise for me - why for GHz processors interrupts each hundred milliseconds matter so much but each second is not?

cgroups can be used w/out cgcreate, cgset, cgexec (they are in cgroup-tools package which for Linux Mint distro required additional installation). IMO good description how to do that: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel has good description how to use cgroups w/out cgroup-tools package (w/out cgcreate,cgset,cgexec), how how to start a process in cgroup: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/starting_a_process.

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000
sudo cgset -r cpu.max="200000 100000" mygroup1 
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

User cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage (this syntax changes 1st value only):
sudo cgset -r cpu.max=100000 mygroup1

Notes for cgroups:

cpu.max has two values: the first value is the allowed time quota in microseconds for which all processes collectively in a child group can run during one period. The second value specifies the length of the period. For multicore/multiprocessor systems 1st is quota for all cores, 2nd is for one, so setting 1st two times greater than 2nd is expected to result in CPU usage of 2 divided by total number of cores.

On my system min valid value is 1000, max is 1000000.

Using second value of 100000 (default) resulted in additional 2x-3x speed penalty when I run ffmpeg, using 1000000 resulted in no noticable penalty.

Surprise for me - why for GHz processors interrupts each hundred milliseconds matter so much but each second is not?

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel has good description how to use cgroups w/out cgroup-tools package (w/out cgcreate,cgset,cgexec), how to start a process: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/starting_a_process.

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000
sudo cgset -r cpu.max="200000 100000" mygroup1 
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

User cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage (this syntax changes 1st value only):
sudo cgset -r cpu.max=100000 mygroup1

Notes for cgroups:

cpu.max has two values: the first value is the allowed time quota in microseconds for which all processes collectively in a child group can run during one period. The second value specifies the length of the period. For multicore/multiprocessor systems 1st is quota for all cores, 2nd is for one, so setting 1st two times greater than 2nd is expected to result in CPU usage of 2 divided by total number of cores.

On my system min valid value is 1000, max is 1000000.

Using second value of 100000 (default) resulted in additional 2x-3x speed penalty when I run ffmpeg, using 1000000 resulted in no noticable penalty.

Surprise for me - why for GHz processors interrupts each hundred milliseconds matter so much but each second is not?

cgroups can be used w/out cgcreate, cgset, cgexec (they are in cgroup-tools package which for Linux Mint distro required additional installation). IMO good description how to do that: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel, how to start a process in cgroup: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/starting_a_process.

added 866 characters in body
Source Link
Martian2020
  • 1.5k
  • 2
  • 12
  • 33

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
sudo cgset -r cpu.max=5 mygroup1
cgset: cgroup modify error: Invalid argument 
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000

trial and error: correct max value on my system >=1000 (and sudo cgcreate -g '*:mygroup2' had not worked either: no error after the command but no folder /sys/fs/cgroup/mygroup2 created).

sudo cgset -r cpu.max=10000max="200000 100000" mygroup1 
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

userUser cannot start process with cgroupscgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage (this syntax changes 1st value only):
sudo cgset -r cpu.max=100000 mygroup1

Notes for cgroups:

cpu.max has two values: the first value is the allowed time quota in microseconds for which all processes collectively in a child group can run during one period. The second value specifies the length of the period. For multicore/multiprocessor systems 1st is quota for all cores, 2nd is for one, so setting 1st two times greater than 2nd is expected to result in CPU usage of 2 divided by total number of cores.

On my system min valid value is 1000, max is 1000000.

Using second value of 100000 (default) resulted in additional 2x-3x speed penalty when I run ffmpeg, using 1000000 resulted in no noticable penalty.

Surprise for me - why for GHz processors interrupts each hundred milliseconds matter so much but each second is not?

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel has good description how to use cgroups w/out cgroup-tools package (w/out cgcreate,cgset,cgexec), how to start a process: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/starting_a_process.

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
sudo cgset -r cpu.max=5 mygroup1
cgset: cgroup modify error: Invalid argument 
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000

trial and error: correct max value on my system >=1000 (and sudo cgcreate -g '*:mygroup2' had not worked either: no error after the command but no folder /sys/fs/cgroup/mygroup2 created).

sudo cgset -r cpu.max=10000 mygroup1
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

user cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage:
sudo cgset -r cpu.max=100000 mygroup1

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000
sudo cgset -r cpu.max="200000 100000" mygroup1 
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

User cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage (this syntax changes 1st value only):
sudo cgset -r cpu.max=100000 mygroup1

Notes for cgroups:

cpu.max has two values: the first value is the allowed time quota in microseconds for which all processes collectively in a child group can run during one period. The second value specifies the length of the period. For multicore/multiprocessor systems 1st is quota for all cores, 2nd is for one, so setting 1st two times greater than 2nd is expected to result in CPU usage of 2 divided by total number of cores.

On my system min valid value is 1000, max is 1000000.

Using second value of 100000 (default) resulted in additional 2x-3x speed penalty when I run ffmpeg, using 1000000 resulted in no noticable penalty.

Surprise for me - why for GHz processors interrupts each hundred milliseconds matter so much but each second is not?

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel has good description how to use cgroups w/out cgroup-tools package (w/out cgcreate,cgset,cgexec), how to start a process: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/starting_a_process.

Source Link
Martian2020
  • 1.5k
  • 2
  • 12
  • 33

Disclaimer: this answer is for benefit of those who find that QA and want to control processes run by themselves and want to limit CPU usage regardless of current total loads of the system.

I've found on my Linux Mint cpulimit did not help. Two ways worked though:

  1. cputool: e.g. cputool -c 10 -- stress -c 4

(stress is (IMO) small useful testing tool to stress test the system)

Downside: cannot as easily change usage once started.

  1. cgroups

Code (surprisingly if I delete this line code formatting below messes up):

sudo cgcreate -g cpu:mygroup1
sudo cgset -r cpu.max=5 mygroup1
cgset: cgroup modify error: Invalid argument 
cat /sys/fs/cgroup/mygroup1/cpu.max # not necessary, tried to find reason for error and tech details for reference 
max 100000

trial and error: correct max value on my system >=1000 (and sudo cgcreate -g '*:mygroup2' had not worked either: no error after the command but no folder /sys/fs/cgroup/mygroup2 created).

sudo cgset -r cpu.max=10000 mygroup1
sudo cgexec -g cpu:mygroup1 sudo -u username1 -g groupname1 stress -c 4
stress: info: [125425] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd

user cannot start process with cgroups unless gives access rights, I have not learned how to add rights (I hope it is possible) but instead use sudo.

# in other terminal to change usage:
sudo cgset -r cpu.max=100000 mygroup1