Restrict cpu usage to 25 % per customer base using cgroups

女生的网名这么多〃 提交于 2021-01-05 12:52:16

问题


I want to restrict cpu usage of users to only 25% . For this i am using cgroups.

Here is the guide that I am following : http://kaivanov.blogspot.in/2012/07/setting-up-linux-cgroups-control-groups.html

This guide work with one core cpu machine, but when i am using with the 4 core cpu machine this configuraion doe not work.

Here is my configuration:

 # Configuration file generated by cgsnapshot
mount { 
    cpu = /cgroup/cpu;  
}

group test1 {
    cpu {
        cpu.rt_period_us="1000000";
        cpu.rt_runtime_us="0";
        cpu.cfs_period_us="100000";
        cpu.cfs_quota_us="-1";
        cpu.shares="250";
    }
}

group test2 {
    cpu {
        cpu.rt_period_us="1000000";
        cpu.rt_runtime_us="0";
        cpu.cfs_period_us="100000";
        cpu.cfs_quota_us="-1";
        cpu.shares="500";
    }
}

What i am missing?

Thanks in advance.


回答1:


The configuration you shared just means that test2 will get twice the cpu as test1. Shares are proportional, they don't take machine size into account. If you want to hard-cap the usage for a cgroup, you need to use cfs_period_us and cfs_quota_us. To use 1 core worth of cpu from a machine, set cfs_quota_us to be same as cfs_period_us (100000).



来源:https://stackoverflow.com/questions/28719109/restrict-cpu-usage-to-25-per-customer-base-using-cgroups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!