views:

1642

answers:

4

I have a small VPS server that has a Nginx front end that serves up static media files and passes Django requests back to an Apache 2.2 prefork MPM server running mod_wsgi.

With one (very) small site loaded and working, it's currently using 143MB of 256MB of RAM.

Using the top command I can see that Apache is using 52.9% of available RAM, with memcache in second using 2.1%.

Considering that I'm planning on putting quite a few Django projects on this one server, I'm wondering if there is anything I can do to trim the amount of RAM that Apache is using?

+3  A: 

You might consider using Spawning for deployment.

Jeff Bauer
It looks interesting. Though I do have a question: would you have to run the spawn command for every site again, if the server ever restarted?
Ty
@Ty: I think you'd put spawning in a init script, in the same place apache is now.
nosklo
+2  A: 

you could run Django on FastCGI. nginx could then drive it directly instead of going through Apache.

Javier
+6  A: 

If you want to stick with Apache, a few suggestions, roughly in order of difficulty:

  • use the Apache worker MPM instead of prefork. Real memory used per client connection will be lower, but be aware that the virtual memory allocated for Apache on Linux can appear very high, due to the 8MB Linux allocates for each thread's stack. This doesn't actually matter, unless your VPS is brain-dead and caps virtual memory rather than actual RSS (resident set size) memory. In that case you can learn how to lower the thread stack size here (under the Memory-constrained VPS section).
  • edit your Apache config file and reduce the StartServers, MaxClients, MinSpareThreads, and MaxSpareThreads settings roughly in proportion. The appropriate levels will be a balance between your desired memory usage and the number of concurrent clients you need to be able to serve.
  • switch to mod_wsgi (in daemon mode) instead of mod_python.
Carl Meyer
Thanks for the reply. I'm already currently using MPM and mod_wsgi. Do you know where there's a good guide for configuring Apache in terms of the StartServers, MaxClients, MinSpareThreads, and MaxSpareThreads settings? They're currently set at the defaults.
Ty
Don't have a good guide off-hand, but just look up those directives in the Apache docs, they're pretty logical. Usually I just scale them down from the defaults in proportion, mostly based on setting MaxClients to the number of concurrent connections I think I'll need to serve.
Carl Meyer
+4  A: 

For the record, the OP's use of the term MPM is non sensical. The MPM in Apache isn't an option, you are always using an MPM when using Apache. The choice is which MPM you are using. On UNIX the two main MPMs or Multiprocessing Modules, are prefork and worker. On Windows the winnt MPM is always used. Details about the different MPMs can be found in Apache documentation on Apache web site. In the context of mod_wsgi though, you might be better off reading:

http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

In short though:

  • prefork MPM is multi process/single threaded.
  • worker MPM is multi process/multi threaded.
  • winnt MPM in single process/multi threaded.
Graham Dumpleton
My qustion has been updated with the type of MPM I was using at the time.
Ty