Microservice Optimizations¶
Docker by default gives unlimited access to the host CPU cycles, which could lead to containers taking more that required. The user is capable of limiting this by adding runtime flags when launching a container.
Docker CPUSet¶
The user can limit the number of cores that a container has access to. This can be accomplished by using runtime flag --cpuset-cpus
. This flag is a comma separated list or a hyphen separated range.
Docker CPUSet Example¶
Comma seperated list
docker run -it --cpuset-cpus=2,3 ubuntu:20.04 /bin/bash
Hyphen seperated range
docker run -it --cpuset-cpus=1-3 ubuntu:20.04 /bin/bash
Docker CPUS¶
Docker also provides a runtime flag --cpus
which limits the CPU resources that it is allowed to access. This is different from --cpuset-cpus
in that it does not specify which specific cores that the container will use, rather the total CPU resources out of the total cores.
Docker CPUS Example¶
docker run -it --cpus=1.5 ubuntu:20.04 /bin/bash