On Dec 10, 3:10 am, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> Hello,
>
> First, I'm gonna say that I have DEBUG turned off, and it's not Django's
> fault.
>
> My Django sites seem to eat lots of memory. This is fine, and it isn't a
> huge deal except that I am using all of my VPS's memory plus swap. The
> real solution is to upgrade memory on the VPS, but I'm a poor college
> student so I want to reduce the memory footprint any way I can. I'm
> using mod_python and apache.
>
> I've seen discussion about mod_python specifically where it was
> suggested to set large variables to None when you're done with them.
> Django does most of the grunt work, and my views don't seem to load any
> very large variables. It seems like any variables instantiated by my
> views would go out of scope after the view function has returned, and
> the Python garbage collection will show up.
>
> I'm curious to know if anyone has ever tried to optimize their code to
> reduce the overall memory footprint. I haven't found any blog posts
> about it yet. I'm willing to resort to making my Django code as
> non-persistent as possible. My sites are all low traffic, so
> non-persistent processes plus memcached shouldn't be too terrible, even
> if I get slashdotted. I just need to squeeze out as much as I can out of
> the ram I have. Swapping makes the Django requests painfully slow.
>
> I am running memcached, which does seem to help my sites go faster, but
> it isn't helping the memory footprint go down (obviously.) I'm also
> considering switching to lighttpd. I've read it has a smaller footprint
> than apache. I've also read that mod_wsgi performs better than mod_python.
>
> Please let me know if you have any other ideas! I'm also curious to know
> if anyone thinks that one of the things I mention trying would help or
> hurt. Thanks!

Definitely stop using mod_python and use mod_wsgi instead. When using
mod_wsgi ensure you use daemon mode with single multithreaded process.
Set maximum-requests and inactivity-timeout for daemon process to
ensure that process is recycled to reclaim memory every so often or
when idle. Also ensure that Apache uses worker MPM and not prefork
MPM. Limit maximum number of Apache child processes to 2 with about 25
threads each. The default of one mod_wsgi daemon process with 15
threads would be adequate.

If you want to get even more aggressive about it, add nginx in front
of Apache as proxy and have nginx serve static files, also turn keep
alive off in Apache. This will make static file serving better and
ensure that Apache doesn't hold connections and unnecessarily use
memory doing that.

Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to