<?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>Musings of a Trained Monkey: RubyGems dependency management and memory use...</title>
    <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>RubyGems dependency management and memory use...</title>
      <description>I've been looking into the nebulous matter of &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; memory management &lt;a href="http://www.stevelongdo.com/articles/2006/08/04/typo-4-0-and-memory-reduction"&gt;lately&lt;/a&gt;, using &lt;a href="http://typosphere.org"&gt;Typo4&lt;/a&gt; as my model app.  In my research thus far I have noticed that several of the highest memory using items are from the &lt;a href="http://www.rubygems.org/"&gt;RubyGems&lt;/a&gt; library.  Particularly the &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; object.  After running a few days I have picked up five instances of it taking up nearly 8MB of RAM which is odd because the first time I profiled it there were &lt;b&gt;only&lt;/b&gt; four of them.  I am not sure why &lt;a href="http://www.rubygems.org/"&gt;RubyGems&lt;/a&gt; needs to be in memory after the app initially loads, especially the ~1.5MB &lt;b&gt;SourceIndex&lt;/b&gt; and the 352 &lt;b&gt;Gem::Specification&lt;/b&gt; objects for another ~1.6MB.  Seems like wiring of any dependencies could be done once at start up.  I am not sure if this relates specifically to how &lt;a href="http://typosphere.org"&gt;Typo&lt;/a&gt; uses &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; or if all &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; apps incur the memory overhead penalty for &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt;. If any one with knoweldge of the internal functioning of &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; would take the time to educate me on this it would be much appreciated.  Also if someone could explain why &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; pops up at all since all &lt;a href="http://www.typosphere.org"&gt;Typo&lt;/a&gt; dependencies are deployed into the vendor folder.&lt;br /&gt;
&lt;br /&gt;Another one to watch is the slow accumulation of &lt;b&gt;ActiveRecord::ConnectionAdpaters::MysqlColumn&lt;/b&gt;, up to 217 instances in memory.  Not a particularly large memory hit, but they have steadily grown in number over the last few days.  i may swith over to my &lt;a href="http://www.postgresql.org/"&gt;Postgres&lt;/a&gt; database and see if the same thing happens with its connecton adapter.&lt;br /&gt;&lt;br /&gt;
Finally the allocation of &lt;b&gt;Array&lt;/b&gt; objects is interesting.  The number of instances in use has gone down by roughly -2000 instances but the memory use of the remaining &lt;b&gt;Arrays&lt;/b&gt; has gone up by about 2MB.  I need to explode these &lt;b&gt;Arrays&lt;/b&gt; and see what they hold and why they stick around so long.  Partial output of profiling included below:
&lt;br /&gt;
&lt;br /&gt;Class x852(21194)
&lt;br/ &gt;&lt;b&gt;Gem::Version x709(24981)&lt;/b&gt;
&lt;br/ &gt;&lt;b&gt;ActiveRecord::ConnectionAdapters::MysqlColumn x217(35410)&lt;/b&gt;
&lt;br/ &gt;Regexp x1343(52312)
&lt;br/ &gt;&lt;b&gt;Gem::Dependency x309(53743)&lt;/b&gt;
&lt;br/ &gt;&lt;b&gt;Gem::Version::Requirement x662(59168)&lt;/b&gt;
&lt;br/ &gt;&lt;b&gt;Gem::SourceIndex x1(1563056)&lt;/b&gt;
&lt;br/ &gt;&lt;b&gt;Gem::Specification x352(1714117)&lt;/b&gt;
&lt;br/ &gt;Hash x1257(1858255)
&lt;br/ &gt;String x117204(3869923)
&lt;br/ &gt;&lt;b&gt;Gem::GemPathSearcher x5(7901012)&lt;/b&gt;
&lt;br/ &gt;Array x6093(11102839)&lt;/b&gt;
&lt;br /&gt;
&lt;b&gt;TOTAL == 28496875&lt;/b&gt;
&lt;br /&gt;&lt;br /&gt;
Please do share your experiences with &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; or &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; memory use in the comments.</description>
      <pubDate>Tue, 08 Aug 2006 06:30:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e9ec453d-bde3-40e3-b93d-a56eee868d15</guid>
      <author>Steve Longdo</author>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use</link>
      <category>rails</category>
      <category>rubygems</category>
      <category>typo</category>
      <category>memory</category>
      <category>stats</category>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by Steve Longdo</title>
      <description>A quick way to see this in action is to have lighty setup to manage the fastcgi processes.  This was the "recommended setup at TextDrive" for a very long time.  &lt;br /&gt;Then you will get an "awesome" entry in ~/process_watchdog.log that will tell you your Ruby process was identified as a zombie and that it killed the parent pid, which if you have lightty setup to manage fastcgi it will then be that parent process.  Or if you are lucky the "not even in the TextDrive Acceptable Use Policy" error: &lt;b&gt;problem=used more than 30 cpu seconds over 90 real seconds&lt;/b&gt; will crop up.&lt;br /&gt;&lt;br /&gt;Following &lt;a href="http://help.textdrive.com/index.php?pg=kb.chapter&amp;id=71" rel="nofollow"&gt;their "current" recommended guidelines&lt;/a&gt; for Rails apps, nets you having lightty reporting that connections are refused on the socket and that the backend died.  Check out &lt;a href="http://forum.textdrive.com/viewtopic.php?pid=97082#p97082" rel="nofollow"&gt;this forum thread&lt;/a&gt; and also &lt;a href="http://forum.textdrive.com/viewtopic.php?pid=96526#p96526" rel="nofollow"&gt;this one, where an admin says that &lt;b&gt;memory related kills don't get logged!&lt;/b&gt;&lt;/a&gt;He also lays it at the feet of FreeBSD memory reporting.  So believe what you read in there for sure :-)</description>
      <pubDate>Wed, 16 Aug 2006 03:09:36 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:90d2dc2c-1edb-43a6-83e9-6fa72f97ad13</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-162</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by sprewell</title>
      <description>According to the &lt;a href="http://textdrive.com/aup" rel="nofollow"&gt;Textdrive Acceptable Use Policy&lt;/a&gt;, these are the limits on processes:
&lt;br /&gt;
&lt;br /&gt;*  CPU time: 20 minutes
&lt;br /&gt;* Resident memory:48 megabytes
&lt;br /&gt;    * Virtual memory: 80 megabytes
 &lt;br /&gt;   * Open files: 240
  &lt;br /&gt;  * Running processes: 20
&lt;br /&gt;&lt;br /&gt;
If your processes are dying at ~48 MB in virtual memory, they're not getting killed by Textdrive (or there's some glitch in the memory-monitoring implementation on your server).  I currently have a ruby process running Typo at Textdrive that has a virtual size of 53 MB.  In &lt;a href="http://forum.textdrive.com/viewtopic.php?id=11147" rel="nofollow"&gt;this forum thread at Textdrive&lt;/a&gt;, an administrator and some others say that there should be a log file left behind if your process was killed.  Do you find any log files when your processes are killed? </description>
      <pubDate>Wed, 16 Aug 2006 02:34:35 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5016e2be-a0d4-45b5-b9c4-3cc562420e28</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-161</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by Steve Longdo</title>
      <description>I've seen the "admin ~10MB spike" behaviour on TextDrive as well. &lt;br /&gt; &lt;br /&gt;On my Mac, using the vanilla ./script/server to start Lightty the virtual memory climbs to 53.3MB right out of the gate.  This happens with no page visits or anything.  On TextDrive the virtual size starts lower(~33MB) and then climbs, at around ~48MB vitual size it gets killed. Real size rarely crosses 40MB, so I think there are some other issues at work.  &lt;br /&gt;&lt;br /&gt;The "~10MB spike" is probably just Ruby allocating more heap which it does in 8MB chunks by default.</description>
      <pubDate>Mon, 14 Aug 2006 23:09:04 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:79b5caa2-5b5c-45c2-9d03-4992540557b5</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-160</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by sprewell</title>
      <description>This might be a &lt;a href="http://www.crowdedweb.com/articles/2006/03/22/ruby-on-rails-and-application-memory-consumption-patterns" rel="nofollow"&gt;FreeBSD issue&lt;/a&gt;.  I notice you're on textdrive also, which uses FreeBSD.  Here's &lt;a href="http://forum.textdrive.com/viewtopic.php?id=9177" rel="nofollow"&gt;a post in their forums&lt;/a&gt; about what's probably the same problem.  Testing Typo on textdrive, I find that memory usage jumps 13-16 MB when I access the admin interface and click on the various tabs.  I'm unable to reproduce this on my dev box running mac os x.</description>
      <pubDate>Mon, 14 Aug 2006 22:46:57 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:dd87e60c-e3e4-4eb1-bc2e-3b25348ed439</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-159</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by sprewell</title>
      <description>Are you doing this from within webrick, fastcgi, mongrel?  Because if this turns out to be environment-dependent, you may not find it if you're not using that environment (I say this because typo seems to stay stable around 29 MB in my ab tests.  I haven't tested mongrel but I suspect it's the culprit for memory leaks.).  I suggest you first hit all 3 of those with ab and make sure they're all gobbling up memory.  If only one of them is, there's your problem.</description>
      <pubDate>Fri, 11 Aug 2006 21:06:54 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:254b2878-ad86-439c-886e-3c550c1928ad</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-154</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by Steve Longdo</title>
      <description>Dan - I will do a follow up posting soon with the code I am using to get this information.  It is more or less taken from some code on the Ruby mailing list a few years ago.  I've just put it inside an admin/controller so I can view the profiling info for the ruby thread that is running.  &lt;br /&gt;I am going to clean up the format a bit and see about getting more detail on dumped items.  Ideally make it browseable from an admin page so you can click on the results to dig deeper.  I'll provide it as a patch for Typo at that point.</description>
      <pubDate>Tue, 08 Aug 2006 14:29:01 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:96574ea1-2119-40f2-b4d1-f462336c8cdc</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-150</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by Scott Laird</title>
      <description>Nice hunting.  I'll see what we can do to hunt this down and fix it.</description>
      <pubDate>Tue, 08 Aug 2006 13:49:58 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3dd72cbd-47e5-43ce-a6fd-86b9fdd5e32a</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-148</link>
    </item>
    <item>
      <title>"RubyGems dependency management and memory use..." by Daniel</title>
      <description>Steve,

Can you describe the tools and/or scripts that you're using to do memory profiling for Ruby and Typo? Perhaps I can help by monitoring my Typo installations.

Thanks!
</description>
      <pubDate>Tue, 08 Aug 2006 12:56:02 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:2b1c809c-2ca6-46ee-848d-3b222bfa0cc6</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/08/rubygems-dependency-management-and-memory-use#comment-146</link>
    </item>
  </channel>
</rss>
