From dd0ab650c8ca3d58b9e19d95ae27523a3956d166 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Fri, 9 Sep 2016 14:42:46 +0800 Subject: [PATCH] Adjust doc about threading There are two ways to give other greenthread chance to run: greenthread.sleep(0) or time.sleep(0). Add the second way in threading.rst and recommend the first way for contributors. Also, PyMySQL works well with eventlet [1], and it's the default MySQL DB API driver for oslo.db now[2]. So adjust 'threading model' doc with such info. [1] https://wiki.openstack.org/wiki/PyMySQL_evaluation [2] http://docs.openstack.org/developer/oslo.db/installation.html Change-Id: I1fcf7242a6794d74da16aa5f326887cfa7257a1b --- doc/source/devref/threading.rst | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/doc/source/devref/threading.rst b/doc/source/devref/threading.rst index 9476c354595..da2b2f53527 100644 --- a/doc/source/devref/threading.rst +++ b/doc/source/devref/threading.rst @@ -28,17 +28,22 @@ in the long-running code path. The sleep call will trigger a context switch if there are pending threads, and using an argument of 0 will avoid introducing delays in the case that there is only a single green thread:: - from eventlet import greenthread - ... - greenthread.sleep(0) + from eventlet import greenthread + ... + greenthread.sleep(0) +In current code, time.sleep(0)does the same thing as greenthread.sleep(0) if +time module is patched through eventlet.monkey_patch(). To be explicit, we recommend +contributors use ``greenthread.sleep()`` instead of ``time.sleep()``. MySQL access and eventlet ------------------------- -Queries to the MySQL database will block the main thread of a service. This is -because OpenStack services use an external C library for accessing the MySQL -database. Since eventlet cannot use monkey-patching to intercept blocking -calls in a C library, the resulting database query blocks the thread. +There are some MySQL DB API drivers for oslo.db, like `PyMySQL`_, MySQL-python +etc. PyMySQL is the default MySQL DB API driver for oslo.db, and it works well with +eventlet. MySQL-python uses an external C library for accessing the MySQL database. +Since eventlet cannot use monkey-patching to intercept blocking calls in a C library, +queries to the MySQL database using libraries like MySQL-python will block the main +thread of a service. The Diablo release contained a thread-pooling implementation that did not block, but this implementation resulted in a `bug`_ and was removed. @@ -49,3 +54,4 @@ a discussion of the `impact on performance`_. .. _bug: https://bugs.launchpad.net/cinder/+bug/838581 .. _mailing list thread: https://lists.launchpad.net/openstack/msg08118.html .. _impact on performance: https://lists.launchpad.net/openstack/msg08217.html +.. _PyMySQL: https://wiki.openstack.org/wiki/PyMySQL_evaluation