Archive for category Ruby

Concurrency in Ruby

I ve been using Ruby for quite a while now and there’s a lot of things I like about it. Somehow I m gonna write about something where Ruby is not really good at. Ruby VM is not really known good for handling concurrency.

Upto Version 1.8.7,  Ruby threads  were known as ‘Green Threads‘ as these implementations were not using the native OS kernel threads instead they were using the threads created by the MRI  in the user space thus making its operations quite costly.  In the Ruby version 1.9.2, YARV ( Yet Another  Ruby VM) was integrated with the Ruby VM, here although ‘Green Threads’ were mapped in one-to-one relation with the native kernel threads, they never are excecuted in parallel due to ‘Global Interpreter Lock’ put on by Ruby MRI. This version can never utilize the multi-cored systems efficiently thus Ruby 1.9.2 too was devoid from true concurrency.

Ruby threading models

A better solution for having true concurrency is to rely on the Java VM whose threading model has proven itself over the years and use JRuby.  JRuby  use system kernel Threads and the threads can run parallely in a multi-cored system.

Reference :


Leave a comment