So I am playing with docker for the first time on my mac. I used boot2docker
through the standard tutorial and I am starting a prompt in an ubuntu image.
docker pull ubuntu
docker run -i -t ubuntu /bin/bash
When in docker I started my first experiment, to see if the performance would go down. From the command line I would use the python timeit
module to quickly check some basic performance measures.
$ python3.4 -m timeit '"-".join(str(n) for n in range(100))'
10000 loops, best of 3: 37.7 usec per loop
$ python3.4 -m timeit '"-".join([str(n) for n in range(100)])'
10000 loops, best of 3: 34.2 usec per loop
$ python3.4 -m timeit '"-".join(map(str, range(100)))'
10000 loops, best of 3: 26.2 usec per loop
Docker Python Results
> python3 -m timeit '"-".join(str(n) for n in range(100))'
10000 loops, best of 3: 30 usec per loop
> python3 -m timeit '"-".join([str(n) for n in range(100)])'
10000 loops, best of 3: 26.9 usec per loop
> python3 -m timeit '"-".join(map(str, range(100)))'
10000 loops, best of 3: 20.2 usec per loop
It seems strange that the docker ubuntu, that is running on top of my mac, is actually running python code faster than the python on mac. Is there any reason for why this might be?
EditsI can confirm that both python versions are running in 64 bit.
Mac Pythonpython3 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'
7fffffffffffffff True
Ubuntu Python
python3.4 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'
7fffffffffffffff True
Since the host kernel is shared amongst Docker containers, applications only ship with what they need to run—no more, no less. This makes Docker applications easier and more lightweight to deploy and faster to start up than virtual machines.
Docker is a containerization tool used for spinning up isolated, reproducible application environments. It is a popular development tool for Python developers. The tutorials and articles here will teach you how to include Docker to your development workflow and use it to deploy applications locally and to the cloud.
Docker containers are designed to run anywhere - in an in-house data center, the cloud, or a hybrid and multi-cloud environment. Out of the box, Docker containers tend to outperform other virtualization methods, but they can be further optimized to offer even better performance.
If you want the absolute latest bugfix version of Python, or a wide variety of versions, the official Docker Python image is your best bet. If you want the absolute latest system packages, you'll want Ubuntu 22.04; RedHat 9 is somewhat more conservative, for example including Python 3.9 rather than 3.10.
This is more about the difference in operating systems than about docker performance. Measuring performance of applications can be tricky.
Bottom line is that OS X has a good number of processes that will compete with your test and OS X likely did not give your test a high priority.
A container should perform as well as the native environment (sometimes better) in most cases. But, your test should make the container do work. Docker will need to add overhead when your application is making system calls and accessing I/O, so those should both be included in your test.
IBM wrote a paper on the Linux Container vs. Native env issue last year.
http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With