3e1100a70a
As per convention, we should avoid using "e.g." (we should use "for example" instead). Found and replaced them accordingly; didn't touch instances that looked copy-pasted from stdout. Change-Id: I45aae1a30b872f916744a6a33f6888abe8cf6eb0 Partial-Bug: #1217503
66 lines
2.8 KiB
XML
66 lines
2.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<section xmlns="http://docbook.org/ns/docbook"
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
version="5.0"
|
|
xml:id="threading">
|
|
<title>Threading</title>
|
|
<section xml:id="header">
|
|
<title>Header</title>
|
|
<para>
|
|
</para>
|
|
</section>
|
|
<section xml:id="Threading-model">
|
|
<title>Threading-Model</title>
|
|
<para>
|
|
===============
|
|
<itemizedlist>
|
|
<listitem><para>model of threading, implemented</para></listitem>
|
|
</itemizedlist>
|
|
through using the Python `eventlet [http://eventlet.net/]`_ and
|
|
`greenlet [http://packages.python.org/greenlet/]`_ libraries.
|
|
Green threads use a cooperative model of threading: thread context
|
|
switches can only occur when specific eventlet or greenlet library calls are
|
|
made. For example, sleep and certain I/O calls. From the operating system's point of
|
|
view, each OpenStack service runs in a single thread.
|
|
The use of green threads reduces the likelihood of race conditions, but does
|
|
not completely eliminate them. In some cases, you may need to use the
|
|
``@utils.synchronized(...)`` decorator to avoid races.
|
|
In addition, since there is only one operating system thread, a call that
|
|
blocks that main thread will block the entire process.
|
|
</para>
|
|
</section>
|
|
<section xml:id="Yielding-the-thread-in-long-running-tasks">
|
|
<title>Yielding-The-Thread-In-Long-Running-Tasks</title>
|
|
<para>
|
|
-----------------------------------------
|
|
If a code path takes a long time to execute and does not contain any methods
|
|
that trigger an eventlet context switch, the long-running thread will block
|
|
any pending threads.
|
|
This scenario can be avoided by adding calls to the eventlet sleep method
|
|
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)
|
|
</para>
|
|
</section>
|
|
<section xml:id="MySQL-access-and-eventlet">
|
|
<title>Mysql-Access-And-Eventlet</title>
|
|
<para>
|
|
-------------------------
|
|
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.
|
|
The Diablo release contained a thread-pooling implementation that did not
|
|
block, but this implementation resulted in a `bug`_ and was removed.
|
|
See this `mailing list thread`_ for a discussion of this issue, including
|
|
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
|
|
</para>
|
|
</section>
|
|
</section>
|