得过且过 发表于 2018-5-29 09:28:40

Docker 之 cgroup篇

# docker --version
Docker version 1.10.3, build f476348/1.10.3
以1.10.3这个版本为例,其中跟cgroup 相关的option有如下几个:--blkio-weight                  Block IO (relative weight), between 10 and 1000
--blkio-weight-device=[]      Block IO weight (relative device weight)
--cpu-shares                  CPU shares (relative weight)
--cpu-period                  Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota                     Limit CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus                   CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems                   MEMs in which to allow execution (0-3, 0,1)
--device-read-bps=[]            Limit read rate (bytes per second) from a device
--device-read-iops=[]         Limit read rate (IO per second) from a device
--device-write-bps=[]         Limit write rate (bytes per second) to a device
--device-write-iops=[]          Limit write rate (IO per second) to a device
-m, --memory                  Memory limit
--memory-reservation            Memory soft limit
--memory-swap                   Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--oom-kill-disable            Disable OOM Killer  

  cgroup 子系统 blkio是用来限制block I/O 带宽
  --blkio-weight --> 设置一个权重值,范围在100-1000之间,这跟cpu.shares 类似,是比重分配,而非拒绝的带宽限制,所以只有在不同子系统在争夺带宽的子资源时候这个设定的值才生效
  

--blkio-weight-device=[]
是针对具体的设备设置权重值,这个值会覆盖 -blkio-weight的值
ex:利用cgroup 将/dev/sda 的权重设置成最小
#echo 8:0 100 > blkio.weight_device  

  CPU 子系统:
--cpu-shares
是分配cpu的比例权重,ex:512/1024 后者可以拿到2/3的cpu运行时间,当然也是当存在争夺的时候此分配的值才会生效,一般情况下是不工作的。
--cpu-period / --cpu-quota
这两个option一般是组合使用,可以利用 --cpu-period 设置成1秒,然后将--cpu-quota 设置为0.5秒,那么在cgroup中的进程在1秒内最多运行0.5秒,然后会被强制睡眠,直到进入下一个1秒时间片段
--cpuset-cpus
允许使用CPU的列表, 例如:0-3,10 (主要看server上的CPU数目和core的数目,lscpu可以查看)
--cpuset-mems
允许进程使用的内存节点列表,例如 :0,1
主要手动利用cgroup 控制进程可以访问的内存节点,防止过多的跨内存使用CPU而减慢整个机器的运行速度  Device 子系统
--device-read-bps=[]
设置每秒读磁盘的带宽上限,需要指定设备
--device-read-iops=[]
设置每秒读磁盘的IOPS上限,需要指定设备   
--device-write-bps=[]
设置每秒写磁盘的带宽上限,需要指定设备
--device-write-iops=[]
设置每秒写磁盘的IOPS上限,需要指定设备  

-m, --memory
限制cgroup控制的进程使用memroy的上限,hard limit (绝对不会超过此值)
--memory-reservation
soft limit memory 使用,可以超过这个值
--memory-swap                  
限制cgroup控制的进程使用的swap memory的大小,其中此选项所对应的值是 memory + swarp 的和--oom-kill-disable
打开此开关,那么当进程使用的memory超多的hard limit所限制的内存数目,那么会触发系统的OOM
然后杀掉某一个进程(一般是内存使用最多的进程)  
页: [1]
查看完整版本: Docker 之 cgroup篇