mod_wsgi memory leak?

Posted on

mod_wsgi memory leak? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, nginx, django, mod-wsgi, .

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/

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/ 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?

Solution :

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')

Leave a Reply

Your email address will not be published.