Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker doesn't get 100% of the CPU

We just wrote a CPU intensive application to benchmark Docker images. It's a Java application that approximates the decimals of Pi.

  • If we run java -jar superpi.jar it stresses all the cores and takes 30 seconds
  • If we run docker run fewlaps/superpi it stresses only two of the four cores and takes 70 seconds

The Docker image is running the .jar as we do when running it on the host. Why is the Docker image not as fast as running the .jar locally? We expected some difference between running it locally and running it on Docker, but the process takes double the time.

Is there any way to request that Docker use all the CPU?

BTW, the project is published here on GitHub: Fewlaps/SuperPI

like image 245
Roc Boronat Avatar asked Aug 22 '16 22:08

Roc Boronat


People also ask

How much CPU can a docker container use?

On windows, a container defaults to using two CPUs. If hyperthreading is available this is one core and two logical processors. If hyperthreading is not available this is two cores and two logical processors.

Can a docker container use all CPU?

By default, a container has no resource constraints and can use as much of a given resource as the host's kernel scheduler allows. Docker provides ways to control how much memory, or CPU a container can use, setting runtime configuration flags of the docker run command.

What is CPU quota Docker?

0 of Docker onward. The --cpu-quota option specifies the number of microseconds that a container has access to CPU resources during a period specified by --cpu-period. As the default value of --cpu-period is 100000, setting the value of --cpu-quota to 25000 limits a container to 25% of the CPU resources.

Is Docker resource intensive?

The lightweight architecture of Docker containers is less resource-intensive than virtual machines. In the case of a virtual machine, resources like CPU, memory, and I/O may not be allocated permanently to containers — unlike in the case of a Docker container, where the resource usage works with the load or traffic.


1 Answers

There are a lot of Docker command line flags related to CPU sets and CPU shares. Make sure that those aren't being set, or specified by default. Once your container is running you can find it with docker ps and see the settings with something like docker inspect gloomy_archimedes and look under the HostConfig section for things like CpuShares, CpusetCpus, etc.

It is also possible that your Docker daemon itself has been limited by its init script or systemd unit definition. You can check that by finding your Docker daemon's PID and cat /proc/1199/status. Look for Cpus_allowed: Should be set to ff.

Or if you are running Docker on Windows or Apple OS X, then Docker will need to use a virtual machine. As far as I know, all Docker images are expecting a Linux operating system environment (although I suppose it is possible someone is building Windows images which would need a VM to run on Linux). That virtual machine will have a configured number of CPU cores. You'll need to find a way to adjust that and make sure it is what you want.

like image 114
Zan Lynx Avatar answered Oct 06 '22 01:10

Zan Lynx