Home > Rails > Monitor Phusion Passenger Memory Usage

Monitor Phusion Passenger Memory Usage

February 10th, 2009

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.

Bill Rails , , ,

  1. Andrei
    July 21st, 2010 at 08:43 | #1

    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

  2. Andrei
    July 21st, 2010 at 08:46 | #2

    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

  3. Andrei
    July 21st, 2010 at 08:50 | #3

    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

  1. No trackbacks yet.