Django memory usage going up with every request

I’m afraid I haven’t got any definite answers. Graham Dumpleton’s tips were most helpfull, but unfortunately he didn’t make an answer (just comments), so there is no way to accept his response.

Although I still haven’t fully resolved the issue, here are some basic tips for other people having similar problems:

  • Read Webfaction’s documentation:
    • Reducing Memory Usage in general
    • Reducing mod_wsgi Memory Consumption
    • Reducing Django Memory Consumption
  • Make sure the DEBUG setting is set to False
  • Don’t use mod_python, use mod_wsgi
  • Make sure you use the most recent version od mod_wsgi (Webfaction tends to install older versions)
  • Don’t use Django to serve static content
  • Try running mod_wsgi in a daemon mode (Webfaction installs it in embedded mode by default) [thanks Graham Dumpleton for the tip]
  • If you run in embeded mode, you can specify “inactivity-timeout=[seconds]” option. It will restart the process after [seconds] of inactivity, helping with increased memory usage. Read this forum post for detailed instructions.
  • This script will help you monitor your memory usage easier, and more precisely [thanks ClaudioA for the tip]

Leave a Comment