# A little confused about threads and VM's

**URL:** <https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324>\
**Category:** Rails\
**Created:** [March 30, 2008, 6:16am UTC](https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324 "2008-03-30T06:16:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 30, 2008, 6:16am UTC](https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324/1 "2008-03-30T06:16:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 30, 2008, 11:16am UTC](https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324/2 "2008-03-30T11:16:51Z")

</div>

On Mar 30, 5:16 am, Ron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 30, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324/3 "2008-03-30T19:21:53Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 30, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/a-little-confused-about-threads-and-vms/133324/4 "2008-03-30T20:54:41Z")

</div>

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
