Reducing RAM resource usage on a VPS
Here are some miscellaneous notes as I tweak a new virtual private server (VPS). It's a time of fear and wonder as I'm leaving FreeBSD's ample and soft bosom for the as yet unknown pleasures to be found in the arms of my new Debian lover.
- HTTP Daemon:
Problem? I think it's self evident. Yes, I know you can tune Apache and yes, I've been down that road before myself, but nothing I've done to tune Apache beats a simple lighttpd implementation, at least not with my application stack.
Solution: Uninstall Apache. Install lighttpd.
As a bonus, lighttpd supports SCGI (and FCGI) natively (to my knowledge, another popular lightweight httpd - nginx - does not support SCGI natively although contribs are available) which gives you deployment options for a variety of popular and not so popular Python web application frameworks.
Incidentally, QP deployed with SCGI (whether via lighttpd or Apache httpd) provides a nice combo that would be compatible with a multi-user shared hosting environment.
One of these days I'll get off my but and migrate my weblog over, and enable comments here in doing so, in order that I can satisfy a selfish desire to ask the lazy web if anyone has worked with a reasonable webmail application developed in Python. I'd really like to avoid supporting PHP in the future and at this point I only support PHP for a webmail application.
- rsyslogd
This daemon appears to be the default system logging daemon on Debian; for some reason it uses many times more RAM than the default FreeBSD syslogd, even when it isn't actually doing any remote logging.
Solution: Add a call to ulimit -s 128 in do_start() in /etc/init.d/rsyslog before the daemon is started to reduce the stack size.
- DNS
bind9 is a huge monster, something not often needed for a VPS or dedicated server that might need to also be an authoritative name server for a few domains. I'm sure there is some tweaking that can be done to reduce its footprint (no threads?) but for a clean break lets try another.
Solution: MaraDNS. Simple to configure (not that bind is all that hard, but some complain just the same), fast, and small. Config file uses Python syntax (n.b. use "somevalue" rather than single quotes 'some value').
Total savings so far: 80 - 120MB (more if one factors in Apache), which is pretty substantial given many low end VPS accounts start at 64 - 128MB of RAM allocation.