Tuesday, February 1, 2011

Dozer and memory profiling Django apps

Installing Dozer:

1. First, you must do the following;
pip install --upgrade dozer
pip install --upgrade paste
2. Next, Apache v2 must be configured to run in WSGI Daemon mode.

  WSGIDaemonProcess myhost.domain.com threads=25
  WSGIProcessGroup myhost.domain.com


The Apache documentation discusses in more detail about how the various configurations for WSGI daemon mode can be configured, but the basic gist is that you should not have a processes= definition and simply define a WSGIDaemonProcess and a WSGIProcessGroup. By doing this, wsgi.multiprocess will be set to False, which is what Dozer needs to work. Otherwise, you will see " "Dozer middleware is not usable in a multi-process environment".

3. You need to then modify your WSGI handler to wrap the Dozer import:
import os, sys
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
from dozer import Dozer

application = django.core.handlers.wsgi.WSGIHandler()
application = Dozer(application)
4. The URL to access Dozer is http:///_dozer/index. From there, you can drill-in to view the spark lines.

5. Dozer was inspired by Dowser, so you can review the documentation to see what to expect:

http://www.aminus.net/wiki/Dowser

Other links for tracing memory leaks in Python..

http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks

No comments:

Post a Comment