Threads in JRuby vs standard Ruby

G

Guillermo.Acilu

[Note: parts of this message were removed to make it a legal post.]

Hello guys,

This is the first time I am working with threads and so far it gave me a
good result in the speed of my code, using Ruby 1.8.6 in the native Mac OS
X distribution. By I read in the book "The Ruby Programming language" that
the threads in the standard "C" Ruby 1.8.6 are not real OS threads and
they all share the same main Ruby thread. I have read also that JRuby
implements real OS threads.

My code triggers more than 200 threads each of them with one private
connection to a MySQL database.

Would it be a real advantage to use JRuby in this scenario?

Thanks,

Guillermo
 
I

Iñaki Baz Castillo

El Martes, 24 de Junio de 2008, (e-mail address removed) escribi=C3=B3:
Hello guys,

This is the first time I am working with threads and so far it gave me a
good result in the speed of my code, using Ruby 1.8.6 in the native Mac OS
X distribution. By I read in the book "The Ruby Programming language" that
the threads in the standard "C" Ruby 1.8.6 are not real OS threads and
they all share the same main Ruby thread. I have read also that JRuby
implements real OS threads.

Read this good document about Ruby threading:
http://www.infoq.com/news/2007/05/ruby-threading-futures

My code triggers more than 200 threads each of them with one private
connection to a MySQL database.

Would it be a real advantage to use JRuby in this scenario?

Well, Ruby threads are "green" threads, this is: they only exist into the R=
uby=20
process but not for the OS so all the threads runned into a Ruby process=20
share the same processor (you get not advantage of a multiprocessor=20
computer).

JRuby uses the Java virtual machine, and that uses real OS threads, but tha=
t's=20
all I know :)




=2D-=20
I=C3=B1aki Baz Castillo
 
I

Iñaki Baz Castillo

El Martes, 24 de Junio de 2008, Zhukov Pavel escribi=C3=B3:
Same problem. But i solve it as DRb + fork.

Could you please give a tip of your solution using Drb + fork?


=2D-=20
I=C3=B1aki Baz Castillo
 
Z

Zhukov Pavel

Y29yZSBhcHAgc3RhcnRzIERSYiBzZXJ2ZXIgd2l0aCBzZWxmIGFzIGZyb250IG9iamVjdC4gdGhl
biwgaSBmb3JrCidwbHVnaW5zJyB0aGF0IGNvbm5lY3QgdG8gY29yZSBhcHAgYW5kICJyZWdpc3Rl
ciIgeW91c2VsZiBpbiBjb3JlJ3MKQHBsdWdpbiBsaXN0LgoKTW9kaWZpZWQgc2lnbmFsIHN5c3Rl
bSBwcm92aWRlIGNvbW11bmljYXRpb24gYmV0d2VlbiBwcm9jZXNzZXMuCgppZiB5b3UgaW50ZXJl
c3RlZDoKaHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3J1ZGNwcC9zb3VyY2UvYnJvd3NlL3RydW5r
L2NvcmUucmIgICNjb3JlIGNsYXNzCmh0dHA6Ly9jb2RlLmdvb2dsZS5jb20vcC9ydWRjcHAvc291
cmNlL2Jyb3dzZS90cnVuay9wbHVnaW5zL3BsdWdpbi5yYgojYWxsIHBsdWdpbnMgc2hvdWxkIGJl
IGJhc2VkIG9uIGl0Cmh0dHA6Ly9jb2RlLmdvb2dsZS5jb20vcC9ydWRjcHAvc291cmNlL2Jyb3dz
ZS90cnVuay9saWIvc2lnbmFsLnJiCiNtb2RpZmllZCBzaWduYWwgc3lzdGVtCgpPbiBUdWUsIEp1
biAyNCwgMjAwOCBhdCA3OjEwIFBNLCBJw7Fha2kgQmF6IENhc3RpbGxvIDxpYmNAYWxpYXgubmV0
PiB3cm90ZToKPiBFbCBNYXJ0ZXMsIDI0IGRlIEp1bmlvIGRlIDIwMDgsIFpodWtvdiBQYXZlbCBl
c2NyaWJpw7M6Cj4+Cj4+IFNhbWUgcHJvYmxlbS4gQnV0IGkgc29sdmUgaXQgYXMgRFJiICsgZm9y
ay4KPgo+IENvdWxkIHlvdSBwbGVhc2UgZ2l2ZSBhIHRpcCBvZiB5b3VyIHNvbHV0aW9uIHVzaW5n
IERyYiArIGZvcms/Cj4KPgo+IC0tCj4gScOxYWtpIEJheiBDYXN0aWxsbwo+Cj4K
 
I

Iñaki Baz Castillo

El Martes, 24 de Junio de 2008, Zhukov Pavel escribi=C3=B3:
core app starts DRb server with self as front object. then, i fork
'plugins' that connect to core app and "register" youself in core's
@plugin list.

Modified signal system provide communication between processes.

if you interested:
http://code.google.com/p/rudcpp/source/browse/trunk/core.rb #core class
http://code.google.com/p/rudcpp/source/browse/trunk/plugins/plugin.rb
#all plugins should be based on it
http://code.google.com/p/rudcpp/source/browse/trunk/lib/signal.rb
#modified signal system

Thanks a lot, it seems interesting.



=2D-=20
I=C3=B1aki Baz Castillo
 
C

Charles Oliver Nutter

Hello guys,

This is the first time I am working with threads and so far it gave me a
good result in the speed of my code, using Ruby 1.8.6 in the native Mac OS
X distribution. By I read in the book "The Ruby Programming language" that
the threads in the standard "C" Ruby 1.8.6 are not real OS threads and
they all share the same main Ruby thread. I have read also that JRuby
implements real OS threads.

My code triggers more than 200 threads each of them with one private
connection to a MySQL database.

Would it be a real advantage to use JRuby in this scenario?

If you would like your app to take advantage of multiple cores without
the complexity of cross-process communication, then JRuby would probably
be a great choice.

- Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top