[dev] threads support in nginx
manlio_perillo at libero.it
Sun Sep 16 22:51:20 MSD 2007
Since mod_wsgi is almost ready, I have to find the best way to not block
nginx when running a WSGI application.
There are two solutions:
1) Implements a Python module for accessing the nginx event module, so
that the application can do asynchronous programming
2) Use threads
The second solution is, unfortunately (I do not like threads) the only
way to support existing applications.
I'm reading the nginx threads support code and, as far as I can understand:
- to execute a job in a separate thread, a module can post an event to
a worker thread
- the code that runs in the separate thread can access the nginx
"internals", since these are protected using a mutex
However there is an alternate method to support threads, and it is the
solution adopted by Twisted (an asynchronous framework written in
Python): when a code that runs in a separate thread needs to access
shared code, it posts back a new event to the main thread.
This solution has the great advantage to simplify the implementation of
thread safe code, since this code is limited to a well defined place,
and the rest of the framework can safely be thread unsafe.
Igor, is this solution applicable to nginx?
 Twisted does not uses events, but callbacks functions
Thanks and regards Manlio Perillo
More information about the nginx