Docker speeds up python, why?

So, this is the first time I am playing docker on my mac. I used boot2docker through a standard tutorial and I run 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 performance would decrease. From the command line, I would use the python timeit module to quickly check some basic performance metrics.

Python Mac Results
 $ 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 
Python Docker 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 docker ubuntu, which runs on top of my mac, actually runs python code faster than python on mac. Is there a reason why this could be?

Edits

I can confirm that both versions of python work in 64 bit.

Mac python
 python3 -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 
+6
source share
1 answer

This is more about the difference in operating systems than about docker performance. Measuring application performance can be difficult.

The bottom line is that OS X has a large number of processes that will compete with your test, and OS X probably did not give your test a high priority.

In most cases, the container should perform as well as its own environment (sometimes better). But your test should make the container work. The docker will need to add overhead when your application makes system calls and accesses I / O, so both of these should be included in your test.

Last year, IBM wrote an article about the release of Linux Container vs. Native env.

http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf

0
source

Source: https://habr.com/ru/post/979234/


All Articles