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
- 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
1, the test memory
1.1, does not limit the cpu usage
You can see, cpu use is full
1.2, restart parameter memory limit vessel was added
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
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