<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>border: solid 1px red;: Ronin: A Simple Rails Process Logger</title>
    <link>http://blog.solid1pxred.com/articles/2008/03/20/ronin-a-simple-rails-process-logger</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>development and other things</description>
    <item>
      <title>Ronin: A Simple Rails Process Logger</title>
      <description>&lt;p&gt;&lt;img src="http://blog.solid1pxred.com/files/Picture_3.png" alt="ronin: (in feudal Japan) a wandering samurai who had no lord or master." style="border: solid 1px #DDD;" /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;sub&gt;(from Apple Dictionary)&lt;/sub&gt;
&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;Back in the fall at &lt;a href="http://rmbr.com"&gt;rmbr&lt;/a&gt; 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&amp;#8217;t exactly sure at first which requests were the cause of the growth.&lt;/p&gt;


	&lt;p&gt;Since I didn&amp;#8217;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&amp;#8217;ve only used it with Mongrel). We found the greedy requests and traced the leak to some &lt;span class="caps"&gt;SQL&lt;/span&gt; that was being loaded in one of our views (naughty!) within a few minutes of putting the plugin up on our server.&lt;/p&gt;


	&lt;p&gt;I finally got around to putting this plugin in my repository, so here is how you can try it out:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;script/plugin install http://solid1pxred.com/svn/code/rails/plugins/ronin&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Try it locally by running your server likes this:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;RONIN=on script/server&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;And then just tail the log to watch your requests:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;tail -f log/ronin.log&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;The plugin outputs the stats like so:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;{ :growth =&amp;gt; 0.22, :request_time =&amp;gt; 0.187, :start_rss =&amp;gt; 23416, :end_rss =&amp;gt; 30076, :delta_rss =&amp;gt; 6660, :uri =&amp;gt; '/zombies/4.xml' }&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;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&amp;#8217;ve noticed a discrepancy with the request time against the Rails logger, so this is by no means scientific (yet&amp;#8230; ?), but it gave me a really good approximation to detect those requests that make your server processes grow.
&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;NOTE&lt;/span&gt;: this currently is built for &lt;span class="caps"&gt;POSIX&lt;/span&gt; systems&lt;/strong&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 20 Mar 2008 16:39:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:891a4f46-2915-464a-888d-6aa8d9f20976</guid>
      <author>Tieg Zaharia</author>
      <link>http://blog.solid1pxred.com/articles/2008/03/20/ronin-a-simple-rails-process-logger</link>
      <category>ruby</category>
      <category>ruby on rails</category>
      <category>mysql</category>
      <category>performance</category>
      <category>logging</category>
    </item>
  </channel>
</rss>
