Select Page

How to improve Docker performance with resource control using cgroups

How to improve Docker performance with resource control using cgroups

Docker performance can be affected by a single container that abuses the CPU or memory, which can eventually end up crashing other containers or the entire machine.

Most hosting providers implement QoS (Quality of Service) to improve Docker performance. This includes limiting resources per container and monitoring their usage.

How resource usage impacts Docker performance

The main resources that are shared among containers in a Docker host includes memory, CPU and block I/O.

The resource usage of a container can be seen with the command ‘docker stats container-ID‘. It will list the CPU, memory and I/O usage for that container.

Docker container stats

Docker container stats

 

During less traffic hours, the resources allotted for the containers would be sufficient to manage the load in them and the Docker performance would be fine.

But when traffic peaks or one Docker container suddenly start abusing the resources in the host, the Docker performance would start getting affected.

To improve performance, its vital to limit the resources per container for QoS (Quality of Service). This can be achieved using the ‘cgroups’ (control groups) feature.

Speed up your Docker containers

GET IN TOUCH WITH THE DOCKER EXPERTS NOW!

 

Today, we’ll discuss how to improve Docker performance by limiting the memory and CPU usage in containers using cgroups.

How to improve CPU performance for Docker containers

CPU usage plays a vital role in determining the Docker performance. The CPU share that is allotted to all containers by default is 1024.

If all the containers have this default value set, the available CPU will be shared among them equally. Without CPU limits, one container can use up all the available CPU.

Suppose you need to allot more CPU share to a container or limit the CPU for one container, based on their plans. This can be achieved by setting CPU weights.

In a machine with 3 containers, if one is assigned 1024 CPU share and others are assigned 512 CPU share, then first one will get 50% CPU and others 25% each.

The CPU shares would be divided among the containers based on the total number of containers and the CPU share value assigned to each.

To assign a CPU share to a container during creation or run-time, the ‘-c’ flag can be used with ‘docker run’ command. Here, a CPU share of 512 is assigned:

 

Assign CPU shares for Docker container

Assign CPU shares for Docker container

 

In multi-core machines, the CPU share has to be calculated by considering the number of CPUs also, along with the container count and usage plans.

It is also possible to allocate the CPU usage of a container to a certain CPU core, in a multi-core machine. Many more tweaking can be done based on the requirements.

The cgroups CPU metrics and stats are stored in the files inside the folder ‘/sys/fs/cgroup/cpuacct/docker/container-ID/’ as seen:

 

Docker container CPU stats

Docker container CPU stats

 

[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]


Speed up your Docker containers!

Wish you had more time to focus on your business? Let us help you.

Our engineers will assist you to setup, monitor and manage your Docker infrastructure 24/7.

GET IN TOUCH WITH THE EXPERTS NOW!




Bobcares provides Outsourced Hosting Support and Outsourced Server Management for online businesses. Our services include Hosting Support Services, server support, help desk support, live chat support and phone support.

Submit a Comment

Your email address will not be published. Required fields are marked *

Bobcares
Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.
MORE ABOUT BOBCARES