Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker service Limits and Reservations

Tags:

docker

Docker v1.12 service comes with four flags for setting the resource limits on a service.

--limit-cpu value Limit CPUs (default 0.000)

--limit-memory value Limit Memory (default 0 B)

--reserve-cpu value Reserve CPUs (default 0.000)

--reserve-memory value Reserve Memory (default 0 B)

  1. What is the difference between limit and reserve in this context?

  2. What does the cpu value mean in here? Does this mean number of cores? cpu share? What is the unit?

like image 418
iCode Avatar asked Jul 05 '16 09:07

iCode


People also ask

Is there a limit for Docker container?

Limit Docker Container CPU Usage Just like RAM usage, Docker containers don't have any default limitations for the host's CPU. Giving containers unlimited CPU usage can lead to issues. There are several ways to define how much CPU resources from the host machine you want to assign to containers.

What is Docker memory reservation?

--memory-reservation. Allows you to specify a soft limit smaller than --memory which is activated when Docker detects contention or low memory on the host machine. If you use --memory-reservation , it must be set lower than --memory for it to take precedence.

What is the difference between a resource limit and a resource reservation when scheduling services?

Answer : A resource limit is hard limit for your service, while a reservation is used to find a host with adequate resources for scheduling.

Does Docker Reserve memory?

As others have said, you cannot reserve memory for processes, and therefore containers. However, you could have the node app called from a script that will check the available memory and exit if it is below a certain threshold.


1 Answers

Reserve holds those resources on the host so they are always available for the container. Think dedicated resources.

Limit prevents the binary inside the container from using more than that. Think of controlling runaway processes in container.

Based on my limited testing with stress, --limit-cpu is percent of a core, though if there are multiple threads, it'll spread those out across core's and seems to attempt to keep the total near what you'd expect.

In the below pic, from left to right, was --limit-cpu 4, then 2.5, then 2, then 1. All of those tests had stress set to CPU of 4 (worker threads).

enter image description here

like image 136
Bret Fisher Avatar answered Sep 21 '22 14:09

Bret Fisher