A few months back schmalowsky (not sure of real name) posted to the Passenger issue tracker about a patch to limit Passenger memory usage. It's kind of a brutal patch in that it uses
setrlimit, so if the process tries to allocate too much memory it just dies. But hey, it keeps one Passenger process from gobbling up all the memory on the box, and you don't need Monit to watch it, so, good enough.
That said, the patch is a few months old and the Passenger source code has moved around, so the patch no longer applies cleanly. I've brought it up to date and you can get the diff here. It seems to work fine - when I set it low enough the process gets put down as soon as it exceeds the threshold.
To try this patch out, do something like this:
I fiddled with this patch for quite a while on my Macbook - but
setrlimit(RLIMIT_RSS, nnn) doesn't seem to be taking effect. The function call is returning
0, and a subsequent
getrlimit returns the value that I just set, but the process size grows and grows regardless. Not sure what's up with that. This is on OS X 10.5.7, Darwin Kernel Version 9.7.0. If anyone has insights into that please send them my way, thanks! Update: Eric Hodel tweets "
setrlimit wasn't fully implemented on OS X, RSS and others are missing." Thanks Eric!
Also, mad props to schmalowsky for writing the original code. All I did was juggle it around a bit; the real work was already done. And of course a huge thanks as always to the Phusion guys for Passenger!