Sponsorship

40% off your First Order with GoDaddy.com!

Apr 14, 2008

Rails: "Ronin" A Simple Rails Process Logger


Back in the fall at rmbr we were running into some requests that ate up a bunch of our memory. Since we often call a few dozen xml requests at a time, we weren’t exactly sure at first which requests were the cause of the growth.

Since I didn’t have a lot of experience with the already-existing Ruby performance tools out there, I cooked up a really basic plugin that monitors the growth of your Rails handler (server-agnostic, although I’ve only used it with Mongrel). We found the greedy requests and traced the leak to some SQL that was being loaded in one of our views (naughty!) within a few minutes of putting the plugin up on our server.

I finally got around to putting this plugin in my repository, so here is how you can try it out:
script/plugin install http://solid1pxred.com/svn/code/rails/plugins/ronin

Try it locally by running your server likes this:
RONIN=on script/server

And then just tail the log to watch your requests:
tail -f log/ronin.log

The plugin outputs the stats like so:


As you can see it is pretty simple to load the log into irb, eval it, and sort it or do whatever you want with it. I’ve noticed a discrepancy with the request time against the Rails logger, so this is by no means scientific (yet… ?), but it gave me a really good approximation to detect those requests that make your server processes grow.i => '/zombies/4.xml'.

As you can see it is pretty simple to load the log into irb, eval it, and sort it or do whatever you want with it. I’ve noticed a discrepancy with the request time against the Rails logger, so this is by no means scientific (yet… ?), but it gave me a really good approximation to detect those requests that make your server processes grow.