Bobcares

How to improve Docker performance with resource control using cgroups

by | Oct 26, 2016

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. ]

How to set memory QoS for containers using Docker cgroups

Similar to CPU, the memory limit of containers also plays a crucial role in Docker performance. Memory limits can be set with cgroups, using its memory subsystem.

The default setting is no memory limit, which means that the container can use as much free memory in the host machine as possible.

This is a dangerous setting as one abusive script can crash the entire machine. To set a container’s memory usage to a fixed limit, the flag ‘-m’ is used in ‘docker run’ command.

Assign memory limits for Docker container

Assign memory limits for Docker container

 

In this instance, the container can use 400M memory and 400M swap memory. The swap memory limit can be set to a separate value, if required.

So the container will be limited to 800M total memory usage and will not be able to hog more memory from the host machine.

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

Docker container memory stats

Docker container memory stats

 

[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]

How to achieve block I/O performance for Docker containers

Block I/O (Blkio) bandwidth assigned to the containers is another resource that needs to be limited for Docker performance.

The default setting is to allot equal share of Blkio among the containers, the value being 500. This can be changed using the ‘–blkio-weight’ flag in ‘docker run’.

Assign block I/O limit for Docker containers

Assign block I/O limit for Docker containers

 

Weight that can be set to the ‘–blkio-weight’ flag can be a value between 10 and 1000, depending on the container requirements.

The docker cgroups Blkio metrics and stats are stored in the files inside the folder ‘/sys/fs/cgroup/blkio/docker/container-ID/’.

 

Docker I/O stats for containers

Docker I/O stats for containers

To summarize..

Resource control and constant performance monitoring is crucial for smooth running of a Docker infrastructure.

In this post, we discussed how we improved Docker performance by implementing resource control for QoS using cgroups, in the containers.

Bobcares helps Docker systems deliver high performance through our expert resource management, control and monitoring services.

If you’d like to know how to manage your Docker infrastructure resources to get the best out of them for your business, we’d be happy to talk to you.

 

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!

var google_conversion_label = "owonCMyG5nEQ0aD71QM";


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.

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF