views:

42

answers:

1

I have a nice little threading problem with a library I use to generate and serve dynamic graphs and charts in Zope. See this question for a description of my original problem.

As the website is already in production, I don't have time to debug that library (I'm not an expert in either C nor threading), hence I'm looking for the quick fix. The best idea I could come up with is to use mod_wsgi as some kind of a guard:

WSGIScriptAlias /graphs /path/to/my/app.wsgi
WSGIDaemonProcess mysite user=www-data group=www-data processes=1 threads=1

The wsgi app at /path/to/my/app.wsgi would simply redirect every request to /_graphs which is again handled by Zope. Because I restrict the wsgi app to one process with one thread, it should prevent any threading problems. The website isn't high volume, I don't really care if this costs me some performance. Also, I don't care that the /_graphs URL isn't protected from direct access, the original problem only appears if charts are downloaded concurrently, which only happens when the user views a page with several embedded dynamic charts.

Nevertheless, this "solution" (if it even works) makes the little computer scientist in my head cry like a baby. Any better ideas?

+2  A: 

You don't need to redirect. Do:

WSGIDaemonProcess multithreaded processes=1 threads=15
WSGIDaemonProcess singlethreaded processes=3 threads=1

WSGIScriptAlias / /path/to/my/app.wsgi

WSGIProcessGroup multithreaded

<Location /graphs>
WSGIProcessGroup singlethreaded
</Location>

In other words, spread application across multiple daemon process groups, using Location directive to delegate the specific URLs which are to be handled in the single threaded process group.

Note, one would not normally use 'processes=1' as WSGIDaemonProcess defaults to one process anyway. In this case we do want it, because any use of 'processes' option causes 'wsgi.multiprocess' to be set to True and in this case we still want that flag to be true for 'multithreaded' process so that code knows it is part of multiprocess configuration even though that particular daemon process group only has one process in it.

Graham Dumpleton
That makes sense. And it would be a good excuse to finally move that Zope instance to WSGI. Thanks for your thorough explanation!
piquadrat