Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a django app running through mod_wsgi on Apache 2 (Worker) behind an Nginx reverse proxy (also serving static content). When the app starts to get a bunch of hits concurrently, memory usage will spike from <20% to >96% and the whole application grinds to a halt.

Here are my Apache WSGI configs:

WSGIDaemonProcess djangoboss user=django group=django processes=2 maximum-requests=500 threads=1 python-path=/home/django/django_env/lib/python2.6/site-packages display-name=%{GROUP}
WSGIProcessGroup djangoboss
WSGIScriptAlias / /home/django/django/wsgi/django_wsgi_handler.py

Here to is output from htop:

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command                                                                                                                                           
29551 django      20   0  793M  745M  6868 R 61.0 42.8  1:28.65 (wsgi:djangoboss)   -k start                                                                                                                        
29550 django      20   0  793M  745M  6868 S  0.0 42.8  0:00.01 (wsgi:djangoboss)   -k start
29549 django      20   0  793M  745M  6868 S  0.0 42.8  0:00.00 (wsgi:djangoboss)   -k start
29548 django      20   0  793M  745M  6868 S  0.0 42.8  0:00.00 (wsgi:djangoboss)   -k start
30778 django      20   0  192M  176M  6356 S  0.0 10.2  0:12.15 /home/django/django_env/bin/python /home/django/django/manage.py post_content
27544 django      20   0 86028 43160  6892 S  0.0  2.4  0:00.01 (wsgi:djangoboss)   -k start
27545 django      20   0 86028 43160  6892 S  0.0  2.4  0:12.92 (wsgi:djangoboss)   -k start
27542 django      20   0 86028 43160  6892 S  0.0  2.4  0:00.00 (wsgi:djangoboss)   -k start
27543 django      20   0 86028 43160  6892 S  0.0  2.4  0:00.00 (wsgi:djangoboss)   -k start

I've tried loadbalancing with a second Apache server behind Nginx, but that didn't seem to help much.

The server is Ubuntu 10.04 with apache/mod_wsgi/nginx all installed from the ubuntu repos. Django app is running on Django 1.2.

Any ideas?

share|improve this question
    
Your htop output doesn't match what configuration says should be happening. Your htop output says you have eight site processes but WSGIDaemonProcess lists two. Why the discrepancy? BTW, you do have DEBUG set to False in your Django settings file? –  Graham Dumpleton Aug 11 '10 at 23:55
    
Also since you are forcing a single thread, does that mean your Django site code is not thread safe? Less processes obviously means less memory overall. –  Graham Dumpleton Aug 11 '10 at 23:57
add comment

1 Answer

up vote 0 down vote accepted

I actually have my doubts that mod_wsgi is leaking. My guess is that your Django app is leaking. I have personally never found any evidence of mod_wsgi leaking memory and I run half a dozen mod_wsgi servers.

Django however is a different story. It's a huge project and in some modules there will be some memory leaked. But most (all?) of the known problems have been fixed in Django 1.1+.

So... I am guessing that something in your script is leaking. Are you running any specific code that could cause problems? What kind of test are you running exactly? A full site test with something like siege? Or a simple test on 1 page with ab?

Regardless, please show the code you are running and/or test if you still have memory leaks with something as simple as this:

def hello_world(request):
    return HttpResponse('Hello World!', mimetype='text/plain')
share|improve this answer
    
Turns out that I had a "test query" that was massive in production. Whenever it was trigger (silently via ajax), the server would start to grind... –  erikcw Aug 13 '10 at 2:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.