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

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 <a href="http:// www.loudthinking.com/">DHH's<a/> 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

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