Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Last active August 29, 2015 14:12
Show Gist options
  • Save shanemhansen/3e99566b09087e36d8d5 to your computer and use it in GitHub Desktop.
Save shanemhansen/3e99566b09087e36d8d5 to your computer and use it in GitHub Desktop.
closerange performance
shane@tuva ~ $ time docker run -i -t grahamdumpleton/mod-wsgi-docker:python-3.4  python -c "import subprocess;subprocess.Popen(['/bin/ls'], close_fds=True).wait()"

real	0m0.394s
user	0m0.026s
sys	0m0.057s

shane@tuva ~ $ time docker run -i -t grahamdumpleton/mod-wsgi-docker:python-3.3  python -c "import subprocess;subprocess.Popen(['/bin/ls'], close_fds=True).wait()"

real	0m0.375s
user	0m0.029s
sys	0m0.053s

shane@tuva ~ $ time docker run -i -t grahamdumpleton/mod-wsgi-docker:python-2.7  python -c "import subprocess;subprocess.Popen(['/bin/ls'], close_fds=True).wait()"

real	0m2.152s
user	0m0.028s
sys	0m0.053s

I haven't exactly nailed down the reason python3 is fast but I think it's because they make use of the python _posixsubprocess module: https://github.com/python/cpython/blob/3.3/Modules/_posixsubprocess.c#L220

You can also check your docker daemon to see if it's had it's limits jacked up enough to cause this problem, like this:

shane@tuva ~ $ docker run -i -t grahamdumpleton/mod-wsgi-docker:python-3.4  python -c "import os;print(os.sysconf('SC_OPEN_MAX'))"
524288

real	0m0.355s
user	0m0.027s
sys	0m0.064s

If SC_OPEN_MAX is really high and you're running python 2, I think you'll experience poor performance on Popen with close_fds=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment