<?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: Tag howto</title>
    <link>http://www.stevelongdo.com/articles/tag/howto</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>RubyGems: Single/Multi-tons and memorysize</title>
      <description>There is a line in the &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; source code, &lt;code&gt;@gempath_searcher ||= Gem::GemPathSearcher.new&lt;/code&gt;, from custom_require.rb that seeks to make &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; a Singleton class. For some reason this isn't sufficient as I have seen as many as five instances of it existing in the same thread during profiling of &lt;a href="http://www.typosphere.org"&gt;Typo&lt;/a&gt;.  I am not sure why more than one gets generated. It may relate to &lt;a href="http://www.rubyonraiils.org"&gt;Rails&lt;/a&gt; aliasing the &lt;code&gt;Kernel.require&lt;/code&gt; method after &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; has in custom_require.rb.
&lt;br/&gt;&lt;br/&gt;
Review of the source makes me understand why a &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; instance can be so large, it holds the gem specifications for every gem and version on the load path.  Running locally this is not a big deal, as you probably don't have a lot of gems and their versions installed.  On a shared host though there are tons of gems and versions of gems installed (&lt;b&gt;350+&lt;/b&gt; on my TextDrive server!).
&lt;br/&gt;&lt;br/&gt;
A permanent solution to fix &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; to truly be a Singleton class would probably be something as simple as checking &lt;code&gt;Object.const_defined?(:GemPathSearcher)&lt;/code&gt; to see if the class is already in memory.
&lt;br/&gt;&lt;br/&gt;
A quick alternative would be restricting the gem library path to a gem repository other than the shared host's repository.  This can be done by exporting the &lt;b&gt;GEM_HOME&lt;/b&gt; variable in your shell.  There is also a &lt;b&gt;GEM_PATH&lt;/b&gt; variable that can be used to support multiple repositories.  Examples of how to work with these variables can be found on the &lt;a href="http://wiki.rubyonrails.org/rails/pages/HowToUseMultipleGemRepositories"&gt;Rails wiki&lt;/a&gt;.  It should be possible to make a repository containing just the gems your app needs and nothing else.  This will reduce the memory footprint of &lt;b&gt;Gem::GemPathSearcher&lt;/b&gt; quite a bit, no matter how many instances of them there might be!
 &lt;br /&gt;&lt;br /&gt;
Obviously I am still learning the implications of &lt;a href="http://rubygems.org"&gt;RubyGems&lt;/a&gt; working together with &lt;a href="http://rubyonrails.org"&gt;Rails&lt;/a&gt; apps.  I apologize for you the reader being dragged along on my quest to learn.  Anyone wishing to bring this quest to a quick end just tell me how it ends.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Update:&lt;/strong&gt; I will continue my research until we arrive at the truth.  I still have some other &lt;a href="http://www.rubygems.org"&gt;RubyGems&lt;/a&gt; optimizing techniques to apply.  My hope is using something like the gemconfigure file described &lt;a href="http://www.rubygems.org/read/chapter/4#page73"&gt;in the documentation&lt;/a&gt; will be the difference between the Whole Milk Memory and Skim Milk Memory.  Also I will reformat the code in the post to be pretty tomorrow.  need to add some stuff to scribbish to accomplish this and I want to go to bed now...</description>
      <pubDate>Wed, 09 Aug 2006 03:41:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3df63391-1cf6-4237-b987-aa0823be01ac</guid>
      <author>Steve Longdo</author>
      <link>http://www.stevelongdo.com/articles/2006/08/09/rubygems-single-multi-tons-and-memorysize</link>
      <category>rubygems</category>
      <category>rails</category>
      <category>typo</category>
      <category>memory</category>
      <category>profiling</category>
      <category>howto</category>
    </item>
    <item>
      <title>Rails 1.1, Textdrive, and Typo...</title>
      <description>&lt;a href="http://typoshpere.org"&gt;Typo&lt;/a&gt; doesn't work on the latest version of &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;.  Unfortunately my &lt;a href="http://www.textdrive.com"&gt;current host&lt;/a&gt; has upgraded the system wide gem to 1.1 from 1.0.  I am sure this is causing problems for lots of people.  The quick fix is to run:
&lt;pre&gt;&lt;code class="ruby2"&gt;rake freeze_edge &lt;span class="constant"&gt;REVISION&lt;/span&gt;=3303&lt;/code&gt;&lt;/pre&gt;This essentially makes your &lt;a href="http://typoshpere.org"&gt;Typo&lt;/a&gt; installation run with &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt; 1.0.</description>
      <pubDate>Wed, 29 Mar 2006 01:40:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3f64276f-5e45-4c67-a66f-db8041e29d72</guid>
      <author>Steve Longdo</author>
      <link>http://www.stevelongdo.com/articles/2006/03/29/rails-1-1-textdrive-and-typo</link>
      <category>typo</category>
      <category>ruby</category>
      <category>rails</category>
      <category>textdrive</category>
      <category>howto</category>
    </item>
  </channel>
</rss>
