InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Rubinius adds Multi-VM support

Posted by Werner Schuster on Jan 16, 2008

Sections
Development,
Architecture & Design
Topics
Ruby ,
Performance & Scalability
Tags
Multi-threading ,
Concurrency ,
Rubinius
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

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.