Linux CGroups can allocate resources—such as CPU time, system memory, network bandwidth, or a combination of these—to user-defined groups of tasks (processes) running on the system. The following is mainly to limit the CPU usage. Virmach's CPU usage cannot exceed 50% for more than 2 hours. 1. Install and enable CGroup yum install libcgroup libcgroup-tools numactl -y Enable CGroup systemctl start cgconfig.service 2. Limit the user's CPU usage 1. Add configuration vi /etc/cgconfig.conf Add at the end group users_normal_limit{ cpu{ # Limit CPU usage to 30% cpu.cfs_period_us=100000; cpu.cfs_quota_us=30000; } } Mainly modify cpu.cfs_quota_us to be the ratio of cpu.cfs_period_us. 2. Add restricted users vi /etc/cgrules.conf Add at the end @user cpu users_normal_limit Add restricted user usermod -a -G users root or more usermod -a -G users www usermod -a -G users mysql 3. Use configuration to take effect Set Cgroup service to start at boot systemctl enable cgconfig systemctl enable cgred Restart Cgroup Service systemctl restart cgconfig systemctl restart cgred
grep 'processor' /proc/cpuinfo | sort -u | wc -l 2. Create an isolation group cd /sys/fs/cgroup/cpu mkdir cpu_test Note: After the directory is created, the following files will be automatically generated (Note: This directory cannot be deleted manually. If it is not added to the startup, it will disappear after restart) ls cpu_test/ 3. Modify parameters echo 30000 > /sys/fs/cgroup/cpu/cpu_test/cpu.cfs_quota_us Note: The default value of -1 is unlimited. Now it is changed to 20000, which means cpu.cfs_quota_us is set to 30000, which is 30% relative to cpu.cfs_period_us of 100000. It can be understood that the CPU usage is limited to 30%. 4. Limit the CPU usage of a program top Restriction Program echo process pid >> /sys/fs/cgroup/cpu/cpu_test/tasks Writing multiple processes into tasks means sharing 30% of the CPU. 4. Run a CPU-consuming script vi cpu.sh Write #/bin/bash x=0 while [ True ];do x=$x+1 done; Set permissions and run chmod +x cpu.sh sh cpu.sh & Main references: http://note.jues.org.cn/index.php/comment/12, https://www.cnblogs.com/llwxhn/p/12558577.html |
<<: DogYun: Double 12 event, 40% discount on all items, lucky draw, etc.
1.AwardSpace Promotion page: click here to enter ...
Environment: CentOS 1. Install on VPS Log in to t...
MskHost, a foreign merchant, a formal company (IE...
myLoc is a long-established German hosting compan...
G Suite, needless to say, will increase in price ...
ServGrid is an American hosting company. The doma...
TmhHost, a Chinese business, has been introduced ...
EntryDNS has been providing free domain name reso...
Hostpad, an Indian hosting provider, was establis...
QwerCloud is a newly established Chinese business...
CloudCone is a relatively active hosting provider...
DMIT, an American hosting company (operated by Ch...
The first wave of Double 11 activities is here, t...
The VPS provided by Impact VPS is VDR, that is, o...
Scaleway, an online brand that provides cloud hos...