From d139b348a3f9a8683c140feba240b339b892ff1c Mon Sep 17 00:00:00 2001 From: Ryan Day Date: Fri, 30 Dec 2011 00:50:36 -0500 Subject: [PATCH 1/4] Add links to understand the GIL --- docs/scenarios/speed.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst index 5a4bd13b6..025352a6d 100644 --- a/docs/scenarios/speed.rst +++ b/docs/scenarios/speed.rst @@ -11,7 +11,13 @@ Context The GIL ------- +`The GIL`_ (Global Interpreter Lock) is how Python allows multiple threads to operate at the same time. Python's +memory management isn't entirely thread-safe, so the GIL is requried to prevents multiple threads from running +the same Python code at once. +David Beazley has a great `guide`_ on how the GIL operates. He also covers the `new GIL`_ in Python 3.2. His +results show that maximizing performance in a Python application requires a strong understanding of the GIL, +how it affects your specific application, how many cores you have, and where your application bottlenecks are. C Extentions ------------ @@ -20,8 +26,8 @@ C Extentions The GIL ------- - - +`Special care`_ must be taken when writing C extensions to make sure you register your threads +with the interpreter. C Extentions :::::::::::: @@ -56,4 +62,8 @@ Multiprocessing --------------- -.. _`PyPy`: http://pypy.org \ No newline at end of file +.. _`PyPy`: http://pypy.org +.. _`The GIL`: http://wiki.python.org/moin/GlobalInterpreterLock +.. _`Understanding GIL`: http://www.dabeaz.com/python/UnderstandingGIL.pdf +.. _`New GIL`: http://www.dabeaz.com/python/NewGIL.pdf +.. _`Thread State`: http://docs.python.org/c-api/init.html#threads \ No newline at end of file From 13a98300706e27ede09e0212dab37eb84c6a144a Mon Sep 17 00:00:00 2001 From: Ryan Day Date: Fri, 30 Dec 2011 00:52:03 -0500 Subject: [PATCH 2/4] fix link markup --- docs/scenarios/speed.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst index 025352a6d..00aa5d50a 100644 --- a/docs/scenarios/speed.rst +++ b/docs/scenarios/speed.rst @@ -64,6 +64,6 @@ Multiprocessing .. _`PyPy`: http://pypy.org .. _`The GIL`: http://wiki.python.org/moin/GlobalInterpreterLock -.. _`Understanding GIL`: http://www.dabeaz.com/python/UnderstandingGIL.pdf +.. _`guide`: http://www.dabeaz.com/python/UnderstandingGIL.pdf .. _`New GIL`: http://www.dabeaz.com/python/NewGIL.pdf -.. _`Thread State`: http://docs.python.org/c-api/init.html#threads \ No newline at end of file +.. _`Special care`: http://docs.python.org/c-api/init.html#threads \ No newline at end of file From 96521d2d02d2468fc34a387f68aaabbbfdcdfee1 Mon Sep 17 00:00:00 2001 From: Ryan Day Date: Wed, 4 Jan 2012 23:00:09 -0500 Subject: [PATCH 3/4] Add benchmarks --- docs/scenarios/speed.rst | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst index 9a559feef..8e18b5bdc 100644 --- a/docs/scenarios/speed.rst +++ b/docs/scenarios/speed.rst @@ -3,7 +3,28 @@ Speed CPython, the most commonly used implementation of Python, is slow for CPU bound tasks. `PyPy`_ is fast. -.. todo:: Fill in stub for Speed comparisons +Using a slightly modified version of `David Beazleys`_ CPU bound test code(added loop for multiple tests), you can see the difference between CPython and PyPy's processing. + +.. pypy:: + $ ./pypy -V + Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10) + [PyPy 1.7.0 with GCC 4.4.3] + $ ./pypy measure2.py + 0.0683999061584 + 0.0483210086823 + 0.0388588905334 + 0.0440690517426 + 0.0695300102234 + +.. python:: + $ ./python -V + Python 2.7.1 + $ ./python measure2.py + 1.06774401665 + 1.45412397385 + 1.51485204697 + 1.54693889618 + 1.60109114647 Context ::::::: @@ -67,4 +88,5 @@ Multiprocessing .. _`The GIL`: http://wiki.python.org/moin/GlobalInterpreterLock .. _`guide`: http://www.dabeaz.com/python/UnderstandingGIL.pdf .. _`New GIL`: http://www.dabeaz.com/python/NewGIL.pdf -.. _`Special care`: http://docs.python.org/c-api/init.html#threads \ No newline at end of file +.. _`Special care`: http://docs.python.org/c-api/init.html#threads +.. _`David Beazleys`: http://www.dabeaz.com/GIL/gilvis/measure2.py From 211106071220bbd55c538d8063f9c45d0bdba0d8 Mon Sep 17 00:00:00 2001 From: Ryan Day Date: Wed, 4 Jan 2012 23:06:19 -0500 Subject: [PATCH 4/4] Fix formatting --- docs/scenarios/speed.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst index 8e18b5bdc..bd83cdecb 100644 --- a/docs/scenarios/speed.rst +++ b/docs/scenarios/speed.rst @@ -5,7 +5,9 @@ CPython, the most commonly used implementation of Python, is slow for CPU bound Using a slightly modified version of `David Beazleys`_ CPU bound test code(added loop for multiple tests), you can see the difference between CPython and PyPy's processing. -.. pypy:: +:: + + PyPy $ ./pypy -V Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10) [PyPy 1.7.0 with GCC 4.4.3] @@ -16,7 +18,9 @@ Using a slightly modified version of `David Beazleys`_ CPU bound test code(added 0.0440690517426 0.0695300102234 -.. python:: +:: + + CPython $ ./python -V Python 2.7.1 $ ./python measure2.py