<div>I wonder if it is possible to reduce the memory footprint of a pack of 6 mongrels by about 70 meg.</div><div>&nbsp;</div>In reading Hongli&#39;s blog about his revisions to Ruby GC (last Monday Matz if he could use Hongli&#39;s work), I was wondering at the size (in RSS) of all the mongrels in a cluster. &nbsp;It has always seemed just too big for my C-binary intuition. &nbsp;Why is so much of the memory of the parent not shared by the children? &nbsp;In other words, why are all the children so bloated? &nbsp;Obviously, something prevents Copy-On-Right from being applied to far more of the memory than I expect. &nbsp;(I expect the stack to be private, and a bit of process-malloc&#39;ed heap).<div>
<br class="webkit-block-placeholder"></div><div>The pmap of a running mongrel says that by far the bulk of the memory immediately following launch is mapped anon / private for</div><div>libruby.so, &nbsp;23M</div><div>libnkf.so &nbsp; &nbsp; &nbsp;6M for kanji</div>
<div>libsyck.so &nbsp; 7M for yaml</div><div><br class="webkit-block-placeholder"></div><div>I guess that is because Ruby is a dynamic language, and always allows for a running proc to modify the optree itself (&#39;monkey patching&#39;). &nbsp;So, in contrast to a compiled binary where the program code is all in the text seg, Ruby keeps the &#39;partly compiled bytecode&#39; optree in private heap, where each proc can mess with it at any time.</div>
<div><br class="webkit-block-placeholder"></div><div>My question is, how important is that privacy? &nbsp;I know lots of modules monkey patch as they load, but I can&#39;t think of any cases where they modify the optree at runtime. &nbsp;I&#39;m sure there are some, but do they happen in 99% of real-world rails apps? &nbsp;I must be overlooking some common cases...?</div>
<div><br class="webkit-block-placeholder"></div><div>But if runtime optree modification is not always required, would it be reasonable to have a flag that would re-mmap() the optree portions of the heap to &#39;read-only&#39; prior to the forking of child servers? &nbsp;The payoff would be that the read-only parts (which may be a couple of dozen meg) could be treated as COW pages, saving them from being copied into each mongrel in a cluster. &nbsp;It just annoys me to think that all these mongrels are burdening the system by lugging around useless private copies of the exact same optree!</div>
<div><br class="webkit-block-placeholder"></div><div>One of the arguments for threading Ruby and Rails is that server procs are so big. DHH has argued that proc-granularity is vastly simpler and safer (bug-wise), and I agree. &nbsp;But I would like to reduce the seeming bloat of a pack of mongrels.</div>
<div><br class="webkit-block-placeholder"></div><div>Another unrelated thought is that I&#39;ve never written a rails app that used Kanji, so why can&#39;t I compile a version of mongrel without NKF? &nbsp;Why don&#39;t most Westerners run app servers without Kanji? &nbsp;The trend in Rails is towards plug-ins for everything except the genuine core, why not apply the same philosophy to app servers?</div>