Docker Performance on a host system vs on a Docker System

With Docker you have an solid way on how to containerize different Applications without cluttering your Host file System. On the one hand, it does run very low on the kernel but on the other hand the Docker Application adds another Layer of Complexity to your application. So if you run your Application directly on the host system then you should expect Maximal Execution speed. Adding a new Layer between your host and the Application you want to run (The Docker Runtime) should not make your program run faster. In this Article we will anaylze this difference in a simple manner and try to evaluate the possible perfomance loss.

System Setup

In my case i am using a Windows 11 Workstation. I’ve already installed some applications on it and using it on a regular basis for my work. I fully acknowledge that this makes reproduction impossible. In addition this may damper the maximal performance. Nevertheless i expect an performance difference between the script running on my host vs. running in a container. For me only the difference is interesting so i can do some basic math with it.

OS Version19044.2846
Docker Version20.10.22
Python Version3.11.2
System SpecsAMD Ryzen 3950X, 128 GB-3600MHz
Table 1: System Specifications

So the next step is to find a way on how to benchmark the system. I’ve decided to split the benchmark up into a CPU test and a memory test, because both are pretty interesting to me.

Testing the CPU

So there are a couple of ways how to test the execution speed of certain programs on your CPU. Since I am doing this kind of testing for the first time, I’ve decided to go for some Hashing Algorithms. The goal is to hash a .png file into several hashes. Here is the picture I am gonna work with:

Source: https://www.pexels.com/de-de/foto/flaches-fokusfoto-des-braunen-hundes-auf-pflanzen-3349216/

So I’ve come up with a simple self-made Python script that uses up all the cores the Host provides. Down below you can see the file, but you can take a look into the whole GitHub Repository by yourself at this Link.

Running this script via PowerShell on the host gives me this funny Looking Task Manager:

Also, I am running this Python script with the following command. This maps the current host drive to a working directory on the docker container. It’s using the python3.11-alpine Image from Docker Hub and executing the script via the python command.

docker run --rm -itv ${PWD}:/usr/py -w "/usr/py" python:3.11-alpine python benchmark.py

The Results

To be serious? The Result blew me away.

System EnvironmentTime (min:seconds.microseconds)
Window 11 Host System @PowerShell01:01.264
Windows 11 Host System @PyCharm01:01.093
Windows 11 Host Sytem @Docker00:50.877
Windows 11 WSL2 Debian @Bash00:49.275
Windows 11 WSL2 Debian @Docker00:50.068
Table 2: The different timing on the different testing scenarios, the less the better

So as you can see, the time even went down on the Docker Architecture. This blew me away! To be honest with you, I am not 100% sure why this is the case. The following lines may or may not be right. Nevertheless, the result should be clear.

In a nutshell, I think Python just isn’t made for Windows. This becomes very clear if we do some simple Math. The overall Performance increase we get is roughly 20%! This becomes very clear if we take another closer Look at the Numbers. The Runtime speed on the sole Windows Platform is about one minute. Compared to all the other Timings – which are all roughly 50 seconds – we can derive that Python just runs smoother on the the-non-windows-engine.

Of course, this could simply be the algorithm of the hash() function and therefore there could be other hashing functions that run faster on Windows, but I simply think that’s not the case.

Overall, I hope you enjoyed this comparison!

Write me an E-Mail!


    Posted

    in

    by

    Comments

    Leave a Reply

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