We are on the cusp of having Passenger running, but I am paranoid, based on our Mongrel experiences, of Passenger instances leaking memory up the wazoo and eventually exhausting our system resources. With Mongrel, we’ve used monit to ensure that memory usage remains intact with each Mongrel, but I hadn’t found a straightforward way to do the same with Phusion yet. So I’m improvising:
kill $(passenger-memory-stats | grep '[56789]..\.. MB.*Rails' | awk '{ print $1 }')
This single line (run via crontab) ought to do what our thousand line monit config file used to do: kill off Rails processes that exceed 500 MB. From my testing so far, it seems to do the trick.
I have verified that it does indeed kill one or multiple Rails processes started by Passenger if their memory usage is reported as being a three digit number that starts with 5-9. Obviously if a Rails instance were able to jump past the 500-999 MB range in less time than the frequency of our cron task, that would be a problem.
Will report back once I’ve witnessed it at work in the wild.
Update from the wild: Yes, it works.
this should work also fine, it will kill every passenger process that takes more than 500 mb
for i in `passenger-memory-stats |grep current|awk ‘{if ($2 > 500) print $1}’`; do echo $i; done
little modification required
for killing passenger processes instead of echo $i
use kill -9 $i
i forget that i used it for simply giving me the ids
one more litlte add
my app was sitting in /mnt/www/app_name/current
so this is why i used “current” for grepping, you”l need to use your app current dir when grepping
Great job man! This single line really rescued my life from dealing with a bunch of scrambling monit code! I’ve used it and trigger it in cron per minute, no OOM any more.
Great one liner for cron! Thank you. It’s currently saving my server from running out of memory after a sudden spate of crazy passengers sucking up everything on the machine.