Way to configure apache for ~125 django sites to optimize memory usage (mod_python v mod_wsgi; worker vs prefork; static files)

djangomemoryoptimizationvirtualhost

I'm currently running 125 Django sites on a single dedicated box at GoDaddy. The sites are relativelly low traffic and I'm wondering what i can do to optimize the memory usage in my apache config. Before I tuned the prefork directives to a lower MaxServer and MaxrequestsPerChild, the box would hang after about 5 hours of being live.

I've been scowering google for answers, but I can't come up with anything definite for the following:

  • Are there any arguments for mod_python vs mod_wsgi in multi site django installs
  • Is there a way to optimize static file serving to conserve memory in apache virtual hosts? (/site_media/ vs media.domain.com)
  • What is the argument for prefork vs worker and memory usage in a multi VirtualNameHost environment?

Current config file included below:

<VirtualHost *:80>
    ServerAdmin webmaster@domain.com
    DocumentRoot /var/www/projectroot/django/chat/static
    ServerName domain.com
    ServerAlias www.domain.com
    Alias /media /usr/lib/python2.5/site-packages/django/contrib/admin/media
    ErrorLog logs/www.domain.com-error_log
    CustomLog logs/www.domain.com-access_log common
    <Location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonPath "['/var/www/domain/django'] + sys.path"
        SetEnv DJANGO_SETTINGS_MODULE chat.settings_domain1 #chat is the name of the project all the sites reside in
        PythonDebug Off
    </Location>
    <Location "/media">
        SetHandler None
    </Location>
    <Location "/site_media">
        SetHandler None
    </Location>
</VirtualHost>

Thanks!
-Tom

Best Answer

I'd definitely go for mod_wsgi. It allows you to define users, number of threads/processes on a per application basis.

I'm not quite sure about the memory requirements but mod_python is considered inferior to mod_wsgi on just about every FAQ or hint you see. WSGIDaemonProcess allows you to configure a lot of options, stacksize, number of processes and the different timeouts may be of interest to you.

I have no experience with GoDaddy so I can't tell you about how far you can go configuring everything.

For the apache part I'd definitely use prefork with the right numbers (depends on your expected user numbers how many childs you want to allow)

For static hosting you could disable all the handlers and even force a certain MIME-Type so that the configuration will just work.

If memory is your bottleneck you might want to check on ngninx from my experience (not that much) memory usage can be predicted a lot better with nginx than with apache, I have no idea about mod-wsgi + ngninx however.