InfoQ

News

Rubinius adds Multi-VM support

Posted by Werner Schuster on Jan 16, 2008

Community
Ruby
Topics
Performance & Scalability
Tags
Rubinius ,
Concurrency ,
Multi-threading
Launching multiple Ruby instances - without having to resort to executing the Ruby binary is available in a few shapes and forms. JRuby allows to have multiple JRuby instances inside one process, each running on its own native thread. For MRI, why the lucky stiff provides the Sandbox Hack to do the same thing.

Recently Rubinius got proper support for launching Multiple Ruby Runtimes, which can be used like this::
vm = Rubinius::VM.spawn "blah", "-e", "puts 'hello\n'"
vm.join
p vm.stdout.gets
To understand the implications of this, we talked to Evan Phoenix of the Rubinius project.

Asked about the idea behind Multi-VM, Evan answers:
I've always know we'd have this kind of functionality in one form or another. The plan for the feature is mixed. Yes, it makes it much easier to start a new VM to do some work. The real question is what that work is and how it's performed [..].
Evan continues with some implementation details:
Currently, each VM is started in it's own native thread (pthread on unix). This lets each VM run without any knowledge of the other VMs and keeps scheduling exactly the same inside the VM.

Rubinius is a very well behaved C program in that it uses no globals or anything, allowing multiple copies of it to mingle in the same address space peacefully.
Since they are running one per native thread, one can crash and bring the whole process down, yes.
Note that the last statement is true of all other Multi VM solutions as well - a JRuby instance that calls global, static methods like System.exit() or uses JNI code that crashes the JVM will bring down all other JRuby instances as well.

Another interesting topic is how to allow the VMs to communicate:
Pipes are one [way], and yes, stdio is redirected to pipes for sub VMs. I've also added a very simple shared message passing system. One VM can send message to another using a single, toplevel mechanism. This mechanism is the only place where one VM interacts with another. It also marshals the messages into it's shared storage, so there is no pointer sharing between the VMs.
The existing shared message passing mechanism could also be extended to use shared memory to allow messages to be passed between [OS] processes easily.
This feature is available in Rubinius git repository now (see InfoQ's coverage of using git to access the Rubinius repository) . If you just want a quick look at the Rubinius source, there's a web interface to the Rubinius git repository. For instance, here the commit for the mentioned message passing system.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.