Docker Diba Hui (docker resource constraints and validation)

https://blog.51cto.com/gouyc

A, docker resource constraints

docker capable of running the kernel depends on two characteristics, namespaces, and CGroups. By default, there is no container resource limits, it can exhaust all resources on the host kernel can be assigned to the container. Therefore, in order to prevent all the resources of the host running a container runs out, we need to use resource limits. And some of the features of resource constraints need linux kernel support Linux Capabilities, version 1.13 before docker, only supports CFS schedule (Completely Fair Scheduler completely fair scheduler), later versions also support realtime schedule

 

CFS schedule: each process has priority, non-priority real-time processes from 100-139, CSF schedule is used to schedule these non-real-time process scheduler, a higher priority process will be executed first cpu

realtime schedule: priority real-time process scheduler, process from 0-99, realtime schedule is dedicated to scheduling real-time process scheduler

 

Two, docker's memory, cpu resource limit parameters

 

1, cpu limit

--cpus = <value>: Specifies how a container cpu resources available can be used, if the core 4 cpu, can be set to 1.5, then 1.5 cpu resources can use up to the core container, if no --cpuset-cpus then 1.5 core can be used can be any of a core resource. This option can only be used in the above docker1.3

--cpu-shares: container prorated cpu resources, cpu resources if other containers are empty, the container 1, if necessary, will use all cpu resources, and assign tasks to any core processing

--cpuset-cpus: Specifies the cpu may be used for the core container which, if cpu and 4, then in accordance with the number to distinguish each of the cores 0-3, this parameter is set to 0, it means that may be used in the first cpu and a second core.

 

2, memory and swap limit

--memory = <value>: Specifies the maximum number of memory can be used as a container, if a process uses more memory than the limit, it might kill off

--memory-swap: container specified as the maximum number of swap space available, this option must be used under the premise of using --memory parameters, if not set --memory parameter, then this parameter will not take effect

image.png

- memory-swappiness: swap containers disposed tendency how, 0-100.

- memory-reservation: soft limit memory usage of container, this means that less than --memory must be set when the system memory is tight, will reclaim lost memory memory value -reservation value of this container, the vessel memory usage down to the standard reservation

--oom-kill-disable: When the container process occurs oom, whether to kill the container


Third, the use of pressure measuring tool for testing

[root@bogon ~]# docker pull lorel/docker-stress-ng
Using default tag: latest
latest: Pulling from lorel/docker-stress-ng
c52e3ed763ff: Pull complete 
a3ed95caeb02: Pull complete 
7f831269c70e: Pull complete 
Digest: sha256:c8776b750869e274b340f8e8eb9a7d8fb2472edd5b25ff5b7d55728bca681322
Status: Downloaded newer image for lorel/docker-stress-ng:latest
 

1, the test memory

1.1, does not limit the cpu usage

[root@bogon ~]# docker container run --name stress -it --rm lorel/docker-stress-ng:latest  --cpu 8
stress-ng: info: [1] defaulting to a 86400 second run per stressor stress-ng: info: [1] dispatching hogs: 8 cpu [root@bogon ~]# docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 92b0b8d916c1 stress 101.54% 15.81MiB / 983.3MiB 1.61% 648B / 0B 0B / 0B 9 [root@bogon ~]# top top - 19:15:49 up 2 days, 2:38, 2 users, load average: 7.02, 3.00, 1.15 Tasks: 131 total, 10 running, 121 sleeping, 0 stopped, 0 zombie %Cpu(s): 99.7 us, 0.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1006892 total, 100680 free, 320704 used, 585508 buff/cache KiB Swap: 2097148 total, 2096628 free, 520 used. 422732 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 40035 root 20 0 6908 4180 252 R 12.6 0.4 0:12.79 stress-ng-cpu 40037 root 20 0 6908 4180 252 R 12.6 0.4 0:12.78 stress-ng-cpu 40038 root 20 0 6908 2136 252 R 12.6 0.2 0:12.78 stress-ng-cpu 40040 root 20 0 6908 2136 252 R 12.6 0.2 0:12.78 stress-ng-cpu 40036 root 20 0 6908 2136 252 R 12.3 0.2 0:12.77 stress-ng-cpu 40039 root 20 0 6908 2136 252 R 12.3 0.2 0:12.78 stress-ng-cpu 40041 root 20 0 6908 4180 252 R 12.3 0.4 0:12.77 stress-ng-cpu 40042 root 20 0 6908 2136 252 R 12.3 0.2 0:12.77 stress-ng-cpu 1 root 20 0 128484 7208 4196 S 0.0 0.7 0:10.12 systemd
 

You can see, cpu use is full

 

1.2, restart parameter memory limit vessel was added

[root@bogon ~]# docker container run --name stress --cpus=0.5 -it --rm lorel/docker-stress-ng:latest  --cpu 8
stress-ng: info: [1] defaulting to a 86400 second run per stressor stress-ng: info: [1] dispatching hogs: 8 cpu [root@bogon ~]# docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 845220ef9982 stress 51.57% 20.05MiB / 983.3MiB 2.04% 648B / 0B 0B / 0B 9
 

Parameter settings take effect

 

2, memory test

2.1, does not limit the use of memory, it specifies the pressure sensing two memory, each 128m

[root@bogon ~]# docker container run --name stress -it --rm lorel/docker-stress-ng:latest  --vm 2 --vm-bytes 128m
stress-ng: info: [1] defaulting to a 86400 second run per stressor stress-ng: info: [1] dispatching hogs: 2 vm [root@bogon ~]# docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS beb3cfa10748 stress 99.29% 256.2MiB / 983.3MiB 26.05% 648B / 0B 0B / 0B 5
 

The actual use of the memory 256M

 

2.2, restart the container, add memory limit

--memory container can only be used to limit the memory 128m

[root@bogon ~]# docker container run --name stress -it --memory=128m --rm lorel/docker-stress-ng:latest  --vm 2 --vm-bytes 128m
stress-ng: info: [1] defaulting to a 86400 second run per stressor stress-ng: info: [1] dispatching hogs: 2 vm [root@bogon ~]# docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS decee18cb471 stress 99.47% 126.4MiB / 128MiB 98.77% 648B / 0B 3.19MB / 461MB 5

 

 

Guess you like

Origin www.cnblogs.com/baomaggie/p/11622769.html