tags:

views:

29

answers:

2

I have a Django app running on Windows (via Apache + mod_wsgi) that's CPU-bound. But Apache on Windows only does MPM (multi-thread) workers, not prefork (multi-process workers), and a single Python interpreter won't take advantage of multiple CPUs.

I would switch to FastCGI, but that requires Flup, which is not supported on Windows.

The only solution I've come up with so far is to start multiple Django instances, then use Apache load-balancing to distribute the requests. That works fine so long as I start the Django instances in command windows, but I can't seem to figure out how to set up multiple Django instances as windows services (so that I get them to start automatically when the system starts).

Has anyone come up with a strategy to get a Django-based site to use multiple CPUs on a Windows server?

A: 

Maybe you can use mod_wsgi's "daemon" mode. Here's some documentation. Look under the heading Modes of Operation and it says it operates similar to FastCGI.

Also, look at the configuration guidelines. Search the page for "daemon" and you'll see a bunch of info on how to set it up.

Evan Porter
sadly, "daemon" mode is only available on Unix. Thanks tho!
Chris Curvey
A: 

I think your question is really "How do you run multiple instances of Apache as windows services?" From the docs:

httpd.exe -k install -n "ApacheBE1" -f "c:\files\my_BE1.conf"
httpd.exe -k install -n "ApacheBE2" -f "c:\files\my_BE2.conf"

Just incase you have that part figured out, did you try setting up more than one heavy weight back-end instances of Apache and load balance among them?

your.host.com:80
 - load balancer / light weight front-end
 - balancing between localhost:9001-900x
localhost:9001
 - mod_wsgi / heavy weight back-end 1
localhost:9002
 - mod_wsgi / heavy weight back-end 2    
localhost:9003
 - mod_wsgi / heavy weight back-end 3    
istruble