I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.
I can clearly see this when I refresh the Django's admin interface in my browser (although this happens with every single page, not only with admin interface - I though admin interface would be a nice test case, because there is no my code directly there). With every browser reload the memory usage goes up couple hundreds kilobytes.
I test the memory using a command suggested by Webfaction:
ps -u publica -o rss,etime,pid,command
More about my setup:
- Django 1.1 (stable)
- Default Webfaction Django setup using Apache and mod_wsgi
DEBUG
set toFalse
- MySQLdb 1.2.2 from Webfaction, but after hearing it had some problems I tried version 1.2.3c. Didn't help.
Edit: I created an empty Django project - default Django configuration plus django.contrib.admin
and fresh empty database (tried both with mysql and postgresql). I started reloading Django admin in my browser and watched memory usage. At first I saw the problem occurring - memory usage grew after every reload. But then it stabilized and stopped growing. That's consistant with how my original project behaved on Django Europe. Unfortunately on Webfaction it never seems to stabilize (or at least not within limits of memory available to my account). Any advice?
I've had issues with memory on Webfaction too - they didn't really crop up until I added my fifth application though. I tried a few tweaks to my apache configs, but what finally worked for me was just switching over to mod_wsgi.
Are both mod_python and mod_wsgi modules loaded into apache?
I know mod_wsgi doesn't like having mod_python in its building. Check its not loaded.
Did you check these tips? -> http://blog.webfaction.com/tips-to-keep-your-django-mod-python-memory-usage-down
We have deploy an app in WebFaction and we are not having those issues.
Are you serving your static files as they recommend?
BTW this could be useful too: http://fightingrabbits.com/archives/198
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:
DEBUG
setting is set toFalse
mod_python
, usemod_wsgi
mod_wsgi
(Webfaction tends to install older versions)mod_wsgi
in a daemon mode (Webfaction installs it in embedded mode by default) [thanks Graham Dumpleton for the tip]Check if the in-process memory cache backend is enabled, if yes, that could be the problem (new cache entries at each request).
We had a similar issue on Webfaction, but it turned out it wasn't because of them at all. There's a bug in Django about high memory usage when using the sitemap with lots of elements: http://code.djangoproject.com/ticket/11572
When we removed the sitemap it doesn't shoot up 90 Mb at the time any longer. Just thought I should mention it since it took a long time for use to troubleshoot.