cgroup中cpu的资源控制

 

参考链接

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/resource_management_guide/sec-cpu#sect-cfs

https://zhuanlan.zhihu.com/p/60199662

 cfs(Completely Fair Scheduler完全公平调度器)

在/sys/fs/cgroup下面,可以看到三个和CPU相关的子系统:cpu,cpuacct,cpuset.
 
Cpu subsystem
cpu子系统用于控制cgroup中所有进程可以使用的cpu时间片
cpu subsystem主要涉及5个接口:cpu.cfs_period_us, cpu.cfs_quota_us,cpu.shares,cpu.rt_period_us,cpu.rt_runtime_us
 
Cpu.cfs_period_us
cfs_period_us表示一个cpu的带宽,单位微秒。整个node节点总cpu带宽是:cpu核数*cfs_period_us
默认值:100000 ( /sys/fs/cgroup/cpu/cpu.cfs_period_us )
 
 
cpu.cfs_quota_us
默认值:-1 (/sys/fs/cgroup/cpu/cpu.cfs_quota_us)
cfs_quota_us表示cgroup可以使用的cpu总带宽,单位微妙。 
cfs_quota_us为-1,表示使用的cpu不受限制。
cfs_quota_us的最小值是1ms(1000),最大值为1s
结合cfs_period_us,就可以限制进程使用的cpu。例如配置cfs_period_us=100000,cfs_quota_us=1500000,表示该容器可以使用总核数为15(cfs_quota_us/cfs_period_us)
 
cpu.shares
默认值: 1024 (/sys/fs/cgroup/cpu/cpu.shares)
通过cfs_period_us和cfs_quota_us可以以绝对比例限制cgrup的cpu使用,即cfs_quota_us/cfs_period_us等于进程可用的cpu cores,不能超过这个值
而cpu.shares以相对比例限制cgroup的cpu。例如:在两个cgroup中都将cpu.shares设定为1的任务将有相同的cpu时间,但在cgroup中将cpu.shares设定为2的任务可以使用的cpu时间是在cgroup中将cpu.shares设定为1的任务可使用的cpu时间的两倍。
 
 
prometheus 监控指标:
container_cpu_cfs_throttled_periods_total  容器生命周期中度过的受限的cpu周期总数
container_cpu_cfs_periods_total   容器生命周期中度过的cpu周期总数

posted on 2022-04-02 17:08  冰冰爱学习  阅读(650)  评论(0编辑  收藏  举报

导航