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.
Ikoula, a French merchant, has its own computer r...
ExCloud, a Chinese merchant, was established in 2...
BandwagonHost, a long-established American hostin...
DMIT, an American hosting provider, mainly provid...
TheStack, a Chinese business, provides virtual ho...
ABC-Server, a Ukrainian hosting provider, was est...
PieLayer, which has been introduced many times, i...
HostXNow, a British hosting provider, was founded...
vpsdime has been introduced many times on this si...
PacificHost is a long-established space provider ...
ZXhost is a British hosting company, founded in 2...
Details : G-CORE: €4.49/month/512MB memory/20GB S...
Sharktech, a long-established American hosting pr...
Mushroom Host is independently operated by Shangh...
CombCloud, a Chinese merchant, was established in...