On Aug 29, 1:39 am, Justin Johnson <[EMAIL PROTECTED]> wrote:
> I've managed to get Django working nicely with CherryPy using WSGI.
> Previously I've deployed Django with Apache and ModPython where each
> requested is serviced by a separate Python instance.

How you think mod_python works is wrong, or at least the way you
explain it is deceiving in its meaning.

In mod_python, each request is not 'serviced by a separate Python
instance'.

In the case of prefork MPM in Apache, although it isn't threaded and
so concurrent requests can't be handled at the same time within a
single interpreter instance, successive requests do get handled in the
same Python interpreter instance. In other words, the interpreter is
not thrown away and instead persists until the process itself is
killed, which may only be when Apache itself is shutdown or restarted.

In the case of worker MPM in Apache, multithreading is used and so
concurrent requests do get handled in the same interpreter at the same
time. Again, the interpreter persists for the life of the process.

Where confusion often arises and why this myth that a separate Python
instance is used for each request persists is that Apache on UNIX is a
multi process web server. Thus your requests aren't necessarily all
handled in the same process, instead they can be distributed across
multiple processes. The use of multiple processes by Apache and the
fact that it can create more on demand as load rises, means that
Apache is much better able to scale than solutions which use a single
Python process with web server implemented in Python only.

I really wish this myth about mod_python would die. :-(

For a bit more information about the process/interpreter model in
mod_python read:

  http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel

> This isn't the case with CherryPy though as it's thread based which
> leads me to the following concern:  is it safe to serve Django with
> CherryPy?

If one takes the warning in mod_python documentation that only prefork
MPM for Apache should be used and worker MPM should not, then it would
follow that using the CherryPy multithreaded web server would not be
safe. Similarly, it wouldn't be safe to run Django on Windows with
Apache either.

In practice, discussions in the past have indicated that there are no
known multithreading problems in Django itself. Thus the warnings
about avoiding worker MPM and thus multithreaded MPMs may not be
strictly applicable. Now although Django may be safe for
multithreading, you would still need to ensure that your higher level
code implemented in Django is multithread safe. You would also need to
ensure that you are using recent versions of any database adapters and
that they declare themselves as multithread safe.

Most importantly, you should rigorously test your application to
ensure that it is truly safe to use in a multithreaded web server.
Areas which I would suggest you look at closely are use of session
objects as these from memory do not provide a locking mechanism, and
so in an AJAX heavy application which issues lots of concurrent
requests and each handler for them wants to manipulate the same
session object, you might run into problems with the handlers and
sequencing of operations against the session object.

Graham


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to