简体   繁体   中英

Docker and CPU Priority when applying CPU Hogs

I've run into something that I cannot quite wrap my head around so I thought I'd turn to smarter minds than mine.

My problem is that I'm trying to figure out how Docker interacts with the Host CPU and which of Docker and Host have priority use over the resources. I want the CPU usage of the host to take priority over the container.

What I have done so far is I started a regular Ubuntu container and I monitor the performance of that container with cAdvisor. I then ran a CPU hog inside the container using the linux stress tool, hogging all cores.

stress -c 8

After confirming that the container did indeed use 100% CPU I ran the same command on the host hogging all 8 cores. What I expected to see was that that container's CPU usage would drop to close to 0% since the host was now using all the resources. What I instead saw was the following:

CPU Usage of Docker Container

So it would seem the container and the Host evenly share the CPU resources. I've also tried running the stress tool on the host with a niceness value of -20 with the same result as above.

Is there any way setting CPU priority to the host so that Docker container would use almost nothing of the CPU resources when the host was using all of them?

Thankful for any help I can get!

There are several options to limit the processor usage of the containers, by for instance setting cpu-period , cpu-quota and cpuset-cpus .

The following would limit the container processor usage to 33%.

docker run -it --cpu-quota=33000 ubuntu:latest /bin/bash

The options are described in the Docker documentation here: https://docs.docker.com/engine/reference/run/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM