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