The Artima Developer Community
Sponsored Link

Ruby Community News Forum
Threading in the New Ruby VM

10 replies on 1 page. Most recent reply: Sep 15, 2007 2:23 PM by Fredrik Mollerstrand

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 10 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Threading in the New Ruby VM Posted: Aug 6, 2007 3:12 PM
Reply to this message Reply
Summary
In a series of short interviews, Ruby language creator Yukihiro Matsumoto and Koichi Sasada, implementor of the new Ruby VM, YARV, discuss the directions for the next-generation Ruby runtime. Among the topics discussed is the move to native threads.
Advertisement

Although Ruby has become a very popular language, some developers are still reluctant to use it on enterprise projects due to the allegedly slow performance of the main Ruby interpreter. While alternative Ruby implementations address the performance problem by running Ruby code on the JVM or on the .NET CLR, the core Ruby team has focused its efforts on a new Ruby VM, YARV.

In a series of brief interviews with James Edward Gray, Ruby creator Yukihiro Matsumoto ("Matz") and Koichi Sasada ("Koichi") discuss new features of YARV, expected to be released at the end of this year. Among the topics discussed is threading and, specifically, a move to native threads from the green threads used in the current Ruby interpreter.

First, YARV is simple stack machine which runs pseudo sequential instructions. [The] old interpreter... traverses the abstract syntax tree (AST) naively. Obviously it's slow. YARV compile[s] that AST to YARV bytecode and run[s] it...

Secondly, YARV uses native thread[s] (that's supported by OS) to implement Ruby threads. It means that you can run blocking task[s] in extension libraries... Supporting native threads does not mean that you can run Ruby scripts in parallel on [a] parallel machine such as [one with a] Multi-Core CPU... [because the] current implementation uses [a] Giant VM Lock to avoid synchronization problems...

YARV doesn't change parser/syntax/specs, GC (memory/object management), and extension libraries like String/Array/Hash/Regexp/etc. Therefore your script doesn't run fast[er] on YARV if [the] bottleneck is string processing.

YARV is already publicly available via our Subversion repository. You can fetch and play with it now. But the first public "release" from us will be Christmas 2007...

On the move to native threading, Koichi and Matz note that:

[The] old threading model [uses] green threads, to provide universal threading on every platform that Ruby runs. I think it was [a] reasonable decision 14 years ago, when I started developing Ruby. Time goes by, [the] situation has changed. pthread or similar threading libraries are now available on almost every platform...

Green threads does not work well with libraries using native threads. For example, Ruby/Tk has made huge effort to live along with pthread...

Koichi decided to use native thread[s] for YARV. I honor his decision. [The] only regret I have is we couldn't have continuation support that used our green thread internal structure...

It doesn't mean that every Ruby thread runs in parallel. YARV has [a] global VM lock (global interpreter lock) which only one running Ruby thread has. This decision ... makes us happy because we can run most of the extensions written in C without any modifications... [But] even with native thread approach, no real concurrency can be [achieved] due to the global interpreter lock. Koichi is going to address this issue by Multi-VM approach in the (near) future...

Parallel computing with Ruby is one of my main concern. There are some way[s] to do it, but running Ruby threads in parallel (without Giant VM Lock) on a process, [it] is too difficult to support current C extension libraries because of their synchronization problems... If we have multiple VM instance[s] on a process, these VMs can be run in parallel...

What do you think of the decision to move to native threads in the next-generation Ruby interpreter?


Carfield Yim

Posts: 32
Nickname: carfield
Registered: Sep, 2002

Re: Threading in the New Ruby VM Posted: Aug 7, 2007 2:12 AM
Reply to this message Reply
>> it was [a] reasonable decision 14 years ago

so... Ruby started at 1993?? It is older than Java???

Alex Fabijanic

Posts: 71
Nickname: aleksf
Registered: Aug, 2006

Re: Threading in the New Ruby VM Posted: Aug 7, 2007 3:02 AM
Reply to this message Reply
I really don't know much about Ruby internals, but I'd say these guys should rethink what they're doing.

Currently, Ruby concurrency performance is horrendous:

http://shootout.alioth.debian.org/gp4/fulldata.php?test=message&p1=hipe-2&p2=ruby-0&p3=gcc-2&p4=java-0

With new approach, things are not likely to get significantly better (C++ benchmark uses pthreads, Ruby removed to clearly show Oz,Erlang/C++(pthreads)/C(coroutines) relation):

http://shootout.alioth.debian.org/gp4/fulldata.php?test=message&p1=hipe-2&p2=oz-0&p3=gcc-2&p4=gpp-2

Michael Campbell

Posts: 5
Nickname: mcampbell
Registered: Sep, 2006

Re: Threading in the New Ruby VM Posted: Aug 7, 2007 4:56 AM
Reply to this message Reply
And not every language is going to, nor should it be, great at everything.

Erlang kicks ass at concurrency. Ruby clearly does not. Does it NEED to? I don't know; maybe. But let them solve the bigger problems first.

John Huffaker

Posts: 3
Nickname: jhuffaker
Registered: Jan, 2007

Re: Threading in the New Ruby VM Posted: Aug 7, 2007 5:42 AM
Reply to this message Reply
Yes, ruby is older than Java.

This poster helps with this "which is older" shootouts:
http://www.oreilly.com/pub/a/oreilly/news/languageposter_0504.html

bug not

Posts: 41
Nickname: bugmenot
Registered: Jul, 2004

Re: Threading in the New Ruby VM Posted: Aug 8, 2007 4:51 AM
Reply to this message Reply
Giving up green threads is a very big price. I hope it will be added back at some time (like stackless for python).

Alex Fabijanic

Posts: 71
Nickname: aleksf
Registered: Aug, 2006

Re: Threading in the New Ruby VM Posted: Aug 8, 2007 5:02 AM
Reply to this message Reply
> And not every language is going to, nor should it be,
> great at everything.

I completely agree. But being "not great" is different from being not acceptable. IMO, the Ruby concurrency benchmarks are unacceptable. Especially in the light of the dawning concurrency paradigm shift we are currently facing. That will make them even more unacceptable.

> Erlang kicks ass at concurrency. Ruby clearly does not.
> Does it NEED to? I don't know; maybe. But let them
> m solve the bigger problems first.

The big problem is how you launch your threads. Pthreads need a certain stack size up front. Erlang clearly has better, more lean model for spawning lightweight threads, which makes it scale extremely well in concurrent scenarios. Nowadays, I don't think any language can ignore concurrency performance and be around for any significant amount of time.

CB

Posts: 5
Nickname: broken
Registered: Aug, 2004

Re: Threading in the New Ruby VM Posted: Aug 8, 2007 5:27 AM
Reply to this message Reply
The concurrency benchmark is nonsense. There is nothing at all concurrent about it. Run 2 independent tasks in threads in Java or C++ and you will get a 2x speed up. With Ruby you get nothing. That is what concurrency is about.

bug not

Posts: 41
Nickname: bugmenot
Registered: Jul, 2004

Re: Threading in the New Ruby VM Posted: Aug 8, 2007 5:53 AM
Reply to this message Reply
In ruby 1.8 they just need to start an os thread (optionally) for every green thread and call the external libraries from them and provide a python like GIL interface.

It is way better than to drop green threads.

Alex Fabijanic

Posts: 71
Nickname: aleksf
Registered: Aug, 2006

Re: Threading in the New Ruby VM Posted: Aug 13, 2007 6:20 AM
Reply to this message Reply
> The concurrency benchmark is nonsense. There is nothing at
> all concurrent about it. Run 2 independent tasks in
> threads in Java or C++ and you will get a 2x speed up.
> With Ruby you get nothing. That is what concurrency is
> about.

http://www.sics.se/~joe/apachevsyaws.html

Fredrik Mollerstrand

Posts: 1
Nickname: nejmennej
Registered: Dec, 2006

Re: Threading in the New Ruby VM Posted: Sep 15, 2007 2:23 PM
Reply to this message Reply
The URL cited in the top-post has been moved. This temporarily sent me into a state of paralyzing dismay.

To avoid this happening to you, please note that the interviews can now be found at http://blog.grayproductions.net/articles/the_ruby_vm_serial_interview

k, thx.

Flat View: This topic has 10 replies on 1 page
Topic: Ruby on Rails 2.0 Preview Released Previous Topic   Next Topic Topic: Microsoft Releases IronRuby Preview

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use