Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single docker container slightly outperforming its host in cpu performance: Why?

Tags:

docker

I ran an experiment to compare the CPU performance of a docker container against the CPU performance of the host it is running on.

Cases

A: Benchmark program run on Host machine (Intel i5, 2.6 GHz, 2 processors, 2 cores)
B: Benchmark program run on Docker container running on the same host machine. (No resource limiting is done for container in B. i.e. container has all 1024 cpu shares for itself. No other container is running)

Benchmark program: Numerical Integration

Numerical Integration: is a standard example of a massively parallel program. A standard numerical integration example program written in C++ using OpenMP lib is taken (which has already been tested for correctness). The program is run 11 times by varying number of available threads within the program from 1-11. These 11 runs are done for each case A and B. So a total of 22 runs are done 11 for host and 11 for container.

X axis: Number of threads available in the program

Y axis: indicates performance which is inverse of time (Calculated by multiplying inverse of time to run program, with a constant).

Result enter image description here

Observation

The docker container running on host is slightly outperforming the host machine. This experiment was repeated 4-5 times across 2 different hosts and every time the container performance curve was slightly above host performance curve.

Question

How is the container performance higher than the host machine when the docker container is running on the host itself?

Possible Reason: Higher priority of of the docker cgroup processes?

I am hypothesizing that the processes within the container's cgroup, might be getting a higher process priority leading to a higher performance of the program running within the container as compared to when the program directly runs on the host machine. Does this sound like a possible explanation?

like image 869
Pranjal Mittal Avatar asked Dec 31 '15 09:12

Pranjal Mittal


People also ask

Does Docker container reduce performance?

Sometimes, running under Docker can actually slow down your code and distort your performance measurements. On macOS and Windows, for example, standard Linux-based Docker containers aren't actually running directly on the OS, since the OS isn't Linux.

How many CPUs does 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. On linux, a container defaults to using all available CPUs of the host.

Do containers impact performance?

A study from IBM Research shows that Docker containers introduce a negligible overhead for CPU and memory performance, and that applications running in a container perform equally or better when compared to traditional virtual machine technology in all tests (Felter et al., 2014).

Does Docker have performance overhead?

Docker has a very low overhead, which means that you can simply add up the individual memory usages of the applications you plan to run inside Docker to calculate your memory usage. For some context, a machine with 16GB RAM is likely to be sufficient for running a few standard-sized containers.


1 Answers

Thanks to the comments of @miraculixx and @Zboson, which helped me understand that the container is not really outperforming the host. The strange results (plot in question) were caused because of the different compiler versions being used on host and container while performing the experiment. When Case A & B are run again after updating to the same version of compiler in both container and host, these are the results:

Without optimization flag

enter image description here

With optimization flag -O3

enter image description here

Observation

It can be observed that container has same or slightly less performance than host; which makes sense intuitively. (Without optimization there are a couple of discrepancies)

P.S Apologies for the misleading question title. I wasn't aware that the performance discrepancy could be because of the different compiler versions until the comments were posted.

like image 86
Pranjal Mittal Avatar answered Oct 22 '22 15:10

Pranjal Mittal