On Jul 9, 3:44 am, Jumpfroggy <rocketmonk...@gmail.com> wrote:
> I'm running a bunch of django apps on my shared host with an 80mb
> memory limit. I have a bunch of very low-traffic sites I want to keep
> running, but use as little memory as possible, so my goal is to
> minimize the memory usage for each of these very small sites. I'm
> just starting to learn about apache/python/django memory usage, so I
> figure there's a lot I just don't know right now.
>
> I'm running on webfaction with:
> Apache 2.2.3 with the Prefork MPM
> Python 2.5.2
> Django 1.0.2 (as stated in webfaction's automatic setup, though django/
> __init__.py shows VERSION = (1, 1, 0, 'beta', 1))
>
> I'm measuring against the RSS. A sample of one of my apps:
>
> RSS Command
> 3624 .../apache2/bin/httpd -f .../apache2/conf/httpd.conf -k start
> 15716 .../apache2/bin/httpd -f .../apache2/conf/httpd.conf -k start
>
> In this case, I've got one apache supervisor process using a small
> amount of memory (3.5MB) and a single worker process using a good
> amount (15.3MB). When I first start apache, the worker process starts
> small (<4MB), but increases with the first page access (>12MB) and
> stays there until the next restart.
>
> Ideally, I'd like for the worker threads to release all the memory
> they're using when idle to get back down to their initial memory
> usage. I realize that there will be some performance tradeoffs for
> this, but in this case these sites have very low requirements so it
> seems worth the tradeoff.
>
> I've already played with apache's httpd.conf settings:
> ServerLimit 1
> StartServers 1
> MinSpareServers 1
> In an effort to remove the second worker thread (so I have one process
> using 13mb instead of two). However, at this point apache still
> spawns another process when usage spikes slightly, and then the second
> thread remains until restart.
>
> I've tried investigating apache MPM's, apache settings, and python
> memory profilers, but haven't made much progress. Some things I'd
> like to try to figure out:
> -What is using memory in my apache worker threads? Is that the
> baseline django memory usage, or are there ways to decrease this
> minimum?
> -What python techniques could I be using to decrease the long-term
> memory usage? (not leaks, just persistent memory usage)
> -What apache/wsgi config changes should I be looking into? Different
> MPM?
>
> Any comments/suggestions are appreciated, I know I'm probably missing
> some obvious things here. Thanks.
Apache/mod_wsgi lazily loads WSGI script file and therefore your
application. That is why you only see jump on first request. Django
itself can lazily load stuff only when requests come in for certain
parts of the application. Therefore that base lebel of memory seen on
the first request can still grow later as different parts of the
application are loaded. Eventually it would plateau out. So, what you
are seeing is normal.
Now, because there isn't really a way to have Apache recycle its
process purely based on them being idle, the only choice would be to
use mod_wsgi daemon mode and set up those daemon processes with
inactivity-timeout option. That way if no requests come, process will
be shutdown and restarted and come back to base Apache memory usage.
I would also suggest ensure your application is thread safe and use a
multithreaded daemon process if you can. Because your application is
now in a separate process, you should also consider switching to
worker MPM for Apache so that concurrent requests can be handled for
static files, even if still forced to run a single threaded process
for your application. Of course, if running PHP crud in same Apache,
you will need to stick with prefork MPM.
Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---