九、Docker学习之系统资源限制及验证

OOME

  Out Of Memory Exception
  每一个进程都会有oom_adj(oom计算分数的权重)值,此值越大,oom_score(oom得分)越高,越容易被干掉,因此非常非常重要的容器化应用,一开始就应该调他的oom_adj的值。

  一旦发生OOME,任何进程都有可能被杀死,包括docker daemon在内;为此,Docker特地调整了docker daemon的OOME优先级,以免它被内核“正法”,但容器的优先级并未被调整。

容器内存资源设置

  • –memory-swap
    如果没有设置–memory,那么设置–memory-swap也不会生效。
    在容器内使用free命令可以看到的swap空间并不具有其所展现出的空间指示意义。
--memory-swap--memory功能
正数S正数M容器可用总空间为S,其中ram为M,swap为(S-M),若S=M,则无可用swap资源
0正数M相当于未设置swap(unset)
unset正数M若宿主机(Docker Host)启用了swap,则容器的可用swap为2*M
-1正数M若宿主机(Docker Host)启用了swap,则容器可使用最大至主机上的所有swap空间 的swap资源
  • –oom-kill-disable
    若想在容器占用内存非常大的情况下不被oom杀掉,那么需要将 --oom-kill-disable 设置为 True
  • –memory-swappiness
    –memory-swappiness 设置为0时表示能不用就不用,设置为100时表示能用就用,我们物理服务器也有此参数,在/proc/sys/vm 目录下

CPU

  进程调度器
  非实时优先级:有效范围[100,139];
  使用nas调整优先级,nas的有效范围是[-20,19],0为120,nas越小,非实时优先级数值越小优先级就越高;
  实时优先级:有效范围[0,99] 一般为内核级别的进程;
  cpu 核心数是小于进程数的,当所有进程都需要运行,需要运行的数量大于核心数量的的时候哪个会优先被运行呢?因此我们需要调度器,因此内核中进程管理子系统中最重要的一个组件就是进程调度器,就是调度进程在本地运行的CPU核心之上的,一般非实时优先级为100 - 139,基本进程都是120 ,可通过 奈斯 来调整优先级,范围为[-20,19],还有实时优先级(一般都是内核级的,特别重要的),从0-99,为了调度非实时优先级(100-139之间)的进程,我们有个调度器叫CFS scheduler(完全公平调度器)。
  docker 1.13版本后还支持实时调度。

--cpu-sharescup

   资源共享。按比例切分所有可用。b1为1024权重,b2为512权重,那么b1占2份b2占1份,这个比例分配,如果不需要那就不分配,将所有资源分配给其他需要的容器,假如b2空闲待机状态,那么将100%的资源全给b1

--cpus=<value>

   ​ 限制使用几核cpu

--cpuset-cpus

   限制使用哪个cpu,比如有4核,限制只使用第二个

--cup-period=<value>

   限制使用时长

使用方法

  docker run --help

[root@docNode01 yum.repos.d]# docker run --help

Usage:	docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device weight) (default [])
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
      --cgroup-parent string           Optional parent cgroup for the container
      --cidfile string                 Write the container ID to the file
      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container

验证

  使用 docker-stress-ng 测试,在dockerhub上可查看使用文档
  docker top containerId #查看容器内存使用率

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值