Thanks for your reply; but I am still wondering about a more general 
question. It is my understanding that require 'file.rb' will execute the 
code in file.rb, so if I require the same file in two different ruby 
processes, then I have duplicates of its classes in memory. If I do require 
'c_library.so' then c_library.so will be loaded as a shared library. I 
understand that one process might want to override some methods in file.rb, 
while the other one might depend on the original versions being intact. This 
is a good reason to load the library twice.

In some instances, though, you might know that there are not going to be 
overrides, perhaps child classes at most. In this case the classes (no 
objects) could be shared. Is there a way to do "shared Ruby libraries" and 
have them act like shared C libraries? (This question reveals my ignorance 
of how shared C libraries and OS kernels interact, but I suspect that C (or 
any compiled?) libraries are special.) DRb is not really what I am asking 
about; I mean to share only classes, not objects.

I have plenty of RAM to run my three Mongrel processes, which are already 
overkill for serving a whopping 30 vists and 900 hits per day. (Shameful 
plug of http://www.teamdawg.org if you want to help me out with some more 
load.) Therefore, I am not really trying to do anything, just theorizing.

I have seen widespread criticism of Rails as an poorly-scalable memory hog, 
to which there are replies of, "Optimize your code," (often due to 
ActiveRecord::Base.find generating lots of SELECT * queries) or "Buy more 
RAM and servers until you bring down your database," (which will happen 
pretty quickly with egregious SELECT *), to "Check your logs; your database 
is already the problem." I think Rails is great and Ruby is even greater; in 
fact I want to see them take over the world. It could happen a lot faster if 
we could address criticisms like the above, and when a library is as large 
as ActiveRecord, loading even one time too many is already cause for 
criticism.

Sorry, I started talking about Rails again. The question is not about Rails. 
The questions are: Is there any way we can have shared Ruby libraries 
without turning the relevant code into a C extension? Is it necessary that 
code be compiled to be put into shared memory by the OS? (Feel free to tell 
me I'm being really stupid.) For instance, for all the GTK applications you 
run your system needs to load GTK only once. It would be really nice if this 
could be true of Ruby libraries. I have a feeling that this may just be a 
limitation of interpreted languages. Please explain.


"Jano Svitok" <jan.svitok / gmail.com> wrote in message 
news:8d9b3d920708131157o49bcaba5ibd19f4d1ae2a52ba / mail.gmail.com...
> I suppose the main problem is that Rails (or ActiveRecord, I don't
> know exactly) is not thread-safe. That means you cannot share most of
> its the data. That is the reason why you have to run more mongrels
> compared to a one multi-threaded mongrel.
>
> I don't know where exactly is the problem with rails/ar though, nor
> whether is it at least theoretically solvable.
>