美文网首页
docker容器--cpu-shares选项 2019-05-2

docker容器--cpu-shares选项 2019-05-2

作者: 我是布谷鸟 | 来源:发表于2019-05-22 17:22 被阅读0次

问题:

创建两个容器为 centos1 和 centos2,若只有这两个容器,该怎么设置容器的权重,才能使得centos1和centos2的CPU资源占比为33.3%和66.7%。

准备:

-centos7系统
-docker
-stress软件包(用来有效的消耗cpu资源,模拟高负载场景)

安装stress:

[root@node1 ~]# yum install -y epel-release
[root@node1 ~]# yum -y install stress 

过程:

-宿主机:cpu1 核心1
-使用--cpu-shares int参数
-权重512:1024

运行容器(同一时间内):
centos1:
[root@node1 ~]# docker run -dit --name centos1 --cpu-shares 512 centos/stress bash
e2b4a2546c8ad6449db4197c69daaa37556ee12cee17e85dcc8e6419bf1a663a
[root@node1 ~]# docker run -dit --name centos2 --cpu-shares 1024 centos/stress bash
9b04b81e5dd438203bc7d6e7702b4d74fb7e18a4fd424f5813433f52bdc68061

压力测试:
尽量过载
centos1

[root@e2b4a2546c8a /]# stress -c 4
stress: info: [56] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
[root@node1 ~]# docker stats centos1 
CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
centos1             32.35%              956 KiB / 1.782 GiB   0.05%               1.3 kB / 648 B      0 B / 0 B           0

centos2:

[root@9b04b81e5dd4 /]# stress -c 4
stress: info: [31] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
[root@node1 ~]# docker stats centos2
CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
centos2             66.00%              952 KiB / 1.782 GiB   0.05%               648 B / 648 B       0 B / 0 B           0

答案正确!

如果宿主机有多个cpu或者多个核心:

centos1:

[root@server ~]# docker run -dit --name centos1 --cpu-shares 341 192.168.200.104:5000/centos/stress bash
[root@server ~]# docker stats centos1
CONTAINER           CPU %               MEM USAGE / LIMIT    MEM %               NET I/O             BLOCK I/O           PIDS
centos1             133.20%             980 KiB / 3.86 GiB   0.02%               1.206 kB / 648 B    5.911 MB / 0 B      0

centos2:

[root@server ~]# docker run -dit --name centos2 --cpu-shares 682 192.168.200.104:5000/centos/stress bash
[root@server ~]# docker stats centos2
CONTAINER           CPU %               MEM USAGE / LIMIT    MEM %               NET I/O             BLOCK I/O           PIDS
centos2             266.73%             968 KiB / 3.86 GiB   0.02%               648 B / 648 B       5.895 MB / 0 B      0

总结:

无论宿主机有多少个cpu或者内核,--cpu-shares选项都会按照比例分配cpu资源。
另外只有一个容器时--cpu-shares选项无意义。

附cpu数量查询(一位老哥的文章):
http://www.cnblogs.com/emanlee/p/3587571.html

相关文章

  • docker容器--cpu-shares选项 2019-05-2

    问题: 创建两个容器为 centos1 和 centos2,若只有这两个容器,该怎么设置容器的权重,才能使得cen...

  • Docker四种网格模式

    docker run创建Docker容器时,可以用–net选项指定容器的网络模式,Docker有以下4种网络模式:...

  • Docker的网络模式bridge、host、container

    原文链接 docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下5...

  • Docker的4种网络模式

    我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下4...

  • Docker的4种网络模式

    我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下4...

  • Docker命令-docker exec

    docker exec 原文 描述 在运行的容器中执行命令 使用 选项 docker exec是需要容器处于运行中...

  • 03、容器管理

    1. 创建容器常用选项 查看容器命令帮助:# docker container --help 查看容器文件系统的文...

  • docker镜像制作

    0. Commit镜像docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]] d...

  • Docker命令-docker ps

    docker ps 原文 描述 列出docker容器。 选项 使用示例 一般使用 filter使用 format使...

  • docker.容器管理

    第三节.docker容器管理创建容器常用选项 管理容器常用命令 进入容器的俩种方法

网友评论

      本文标题:docker容器--cpu-shares选项 2019-05-2

      本文链接:https://www.haomeiwen.com/subject/kyguzqtx.html