<?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 memory reduction...</title>
    <link>http://www.stevelongdo.com/articles/2006/08/12/rubygems-memory-reduction</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>RubyGems memory reduction...</title>
      <description>I did gain some insight into the number of &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; instances through my efforts.  They correspond nicely for each piece of &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; that is loaded; ActionMailer, ActiveSupport, ActiveRecord, ActionPack, ActionWebService and Railties. Each of these has the &lt;code&gt;require 'rubygems'&lt;/code&gt; statement in it.  I believe this is why I was seeing multiple instances of &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt;. &lt;br /&gt;
&lt;br /&gt;
As explained before instances of these take up an amount of memory proportional to the number of gems/gem versions in a repository.  Making &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; a Singleton of course, resolves more than one instance being loaded into memory.  This has been submitted as a patch to &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; &lt;a href="http://rubyforge.org/tracker/?func=detail&amp;atid=577&amp;aid=5394&amp;group_id=126"&gt;[ticket #5394]&lt;/a&gt;.
&lt;br /&gt;
&lt;br /&gt;
Installing a patched version of &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; 0.9.0 on &lt;a href="http://www.textdrive.com"&gt;TextDrive&lt;/a&gt; to demonstrate the fix with &lt;a href="http://ww.typosphere.org"&gt;Typo&lt;/a&gt; proved to be the most frustrating part.  I will write a follow up posting on exactly how to do this in the near future.  Hopefully they will release an updated &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; soon!
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.planetargon.com/"&gt;Shared&lt;/a&gt; &lt;a href="http://www.dreamhost.com"&gt;hosts&lt;/a&gt; will definitely want to patch their &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; installs to reduce their memory consumption across all of their &lt;a href="http://www.rubyonrails.org"&gt;Rails&lt;/a&gt; users.  &lt;a href="http://www.textdrive.com"&gt;TextDrive&lt;/a&gt; in particular should buy me a present or something :-) 
&lt;br /&gt;
&lt;br /&gt;
I've learned a great deal about the &lt;a href="http://rubylang.org"&gt;Ruby&lt;/a&gt; memory ecosystem by digging into this issue with &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt;.  I got help from some folks on the &lt;a href="http://www.ruby-forum.com/forum/3"&gt;Rails mailing list&lt;/a&gt; but far and away I want to thank &lt;b&gt;Stef Telford&lt;/b&gt; for the help.  Mad props to you for putting up with all of my questions and ramblings!
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Finally some numbers:&lt;/b&gt;
&lt;br /&gt;
Gem::Dependency x330(57415)
&lt;br /&gt;
Gem::Version::Requirement x693(61939)
&lt;br /&gt;
Gem::SourceIndex x1(1632488)
&lt;br /&gt;&lt;b&gt;Gem::GemPathSearcher2&amp;nbsp;x1(1647806)&lt;/b&gt;&amp;nbsp;&lt;b&gt;&lt;--&lt;/b&gt;&amp;nbsp;&lt;b&gt;Gem::GemPathSearcher&amp;nbsp;x5(7901012)&lt;/b&gt;&lt;br /&gt;
Hash x1219(1789928)
&lt;br /&gt;
Gem::Specification x362(1795089)
&lt;br /&gt;
String x113992(3876455)
&lt;br /&gt;
Array x7415(5080185)
&lt;br /&gt;
&lt;b&gt;TOTAL&amp;nbsp;==&amp;nbsp;16967273&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;--&lt;/b&gt;&amp;nbsp;&lt;b&gt;TOTAL&amp;nbsp;==&amp;nbsp;28496875&lt;/b&gt;
&lt;br /&gt;&lt;br /&gt;
Update:  These memory numbers are lower than actual process size.  They vary by number of Modules loaded as well as Objects counts.  Not all Objects and Modules can be evaluated for memory size.  The new routing code in the latest version of Rails may also account for some of the difference as well.  So grain of salt...</description>
      <pubDate>Sat, 12 Aug 2006 07:00:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:00dbf8e8-5fa9-43f2-9450-d3e6b7e52444</guid>
      <author>Steve Longdo</author>
      <link>http://www.stevelongdo.com/articles/2006/08/12/rubygems-memory-reduction</link>
      <category>typo</category>
      <category>rails</category>
      <category>memory</category>
      <category>rubygems</category>
      <category>profiling</category>
    </item>
    <item>
      <title>"RubyGems memory reduction..." by Steve Longdo</title>
      <description>I updated RubyGems from SVN (r1073) and it resolves the issue.  Sent you an email as well :-)</description>
      <pubDate>Wed, 20 Sep 2006 02:48:03 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:7eb2b2ba-721f-49ed-986a-b94043fad51e</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/12/rubygems-memory-reduction#comment-175</link>
    </item>
    <item>
      <title>"RubyGems memory reduction..." by Jim Weirich</title>
      <description>Steve,

I've updated RubyGems to use a mutex while creating the Gem::GemPathSearcher.  Could you see if it solves your problem?  You can get a beta version with the fix from:

&lt;pre&gt;
   gem update --system --source &lt;a href="http://onestepback.org/betagems" rel="nofollow"&gt;http://onestepback.org/betagems&lt;/a&gt;
&lt;/pre&gt;

Please let me know the results.  Thanks for tracking this down.

-- Jim Weirich
</description>
      <pubDate>Mon, 18 Sep 2006 18:28:26 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:7faa1ebd-78fd-4952-b057-4132223c7a33</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/12/rubygems-memory-reduction#comment-174</link>
    </item>
    <item>
      <title>"RubyGems memory reduction..." by Ben Sinclair</title>
      <description>Nice work, Steve!</description>
      <pubDate>Sat, 12 Aug 2006 14:26:19 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6600facc-e7a5-4e48-badb-4d8d11c039c7</guid>
      <link>http://www.stevelongdo.com/articles/2006/08/12/rubygems-memory-reduction#comment-156</link>
    </item>
  </channel>
</rss>
