A little confused about threads and VM's

Hi,

I’m researching how Ruby works with threads. Could someone help with
what a “green” thread is and a native thread? Also, what is the
relationship between these threads, Rails and the VMs that have been
(are being) built?

Thanks,

Ron

On Mar 30, 5:16 am, Ron [email protected] wrote:

Hi,

I’m researching how Ruby works with threads. Could someone help with
what a “green” thread is and a native thread? Also, what is the
relationship between these threads, Rails and the VMs that have been
(are being) built?

Well this isn’t really a rails question but never mind. Basically, a
native thread is one which maps to the host operating system’s idea of
a thread, green threads are ones that don’t. With native threads
you’ll make use of multiple processor cores, but not with green
threads (since as far as the OS is concerned you only have 1 thread).
An added ‘bonus’ is that some things in ruby will block the entire VM.
MRI uses green threads, jruby uses native threads (IIRC) and i think
ruby 1.9 has native threads (but in some fairly restricted form due to
concerns about extensions backwards compatibility.
If you’re writing a rails app none of this really matters since rails
is single threaded.

Fred

Hi Fred,

Thanks for this and for the help with xml. I guess the thought behind
my question was in trying to understand using a pack of mongrels
behind lighttpd or nginx. I was reading in DHH’s blog about the issue of multi-core
processors and how Rails scales. I was trying to get at why we needed
to set up multiple mongrels to handle loads. I can see now where the
question doesn’t pertain to rails because of the fact that rails is
single threaded.

I’m gathering from the post that the reason we do multiple Mongrels
behind nginx/lighttpd is that, because Rails is single threaded, we
need multiple processes to handle multiple requests at the same
instant?

Ron

On Mar 30, 2:16 am, Frederick C. [email protected]

On 30 Mar 2008, at 18:20, Ron wrote:

Hi Fred,
I’m gathering from the post that the reason we do multiple Mongrels
behind nginx/lighttpd is that, because Rails is single threaded, we
need multiple processes to handle multiple requests at the same
instant?

Correct.

Fred