From: "Wayne E. Seguin" Date: 2007-08-14T03:46:34+09:00 Subject: Re: Why don't Ruby libraries share memory? --Apple-Mail-3-417698472 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Aug 13, 2007, at 14:25 , Matt Harvey wrote: > This paragraph is motivation. While my question is not Rails- > specific, I am asking it because of Rails. I've been investigating > the memory footprint of my Mongrels. It is nice that they share > the .so libraries from ImageMagick as well as other C libraries. > However, each one still has about 20MB in [heap]. My theory is that > a lot of this is coming from ActiveRecord and friends getting > loaded again and again for each Mongrel, which seems to me entirely > unnecessary. My "marginal cost of Apache" is 1376kB. My "marginal > cost of Mongrel" is 27528kB, with the code I wrote. It seems that > the latter could be reduced a lot by sharing some Ruby libraries. > > The question is as follows: if I require 'library' in one instance > of Ruby and then require 'library' again in another instance of > Ruby, then do I get duplicate copies of library's code in two > chunks of my RAM? (I'm thinking I do.) Why? > Matt, Every time you load a Mongrel instance it is loading a completely new Ruby runtime environment which can be modified in any way. If you think about it, if each mongrel instance did share the libraries, when one running application on the system modified some of the library code at runtime it would effect all other running instances. This could be... bad, at best. So to answer what I think is your question, yes you get duplicate copies in two "chunks" of your RAM. Hope this helps, ~Wayne s///g Wayne E. Seguin Sr. Systems Architect & Systems Administrator --Apple-Mail-3-417698472--