From: Eric Hodel Date: 2007-08-14T12:30:13+09:00 Subject: Re: Why don't Ruby libraries share memory? On Aug 13, 2007, at 11: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? You'll get closer to the behavior you expect if you use Kernel#fork to spawn new instances rather than starting up from the shell. This is how Apache costs only 1376kB. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars