[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Threads in JRuby vs standard Ruby

Guillermo.Acilu

6/24/2008 2:24:00 PM

[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

5 Answers

Iñaki Baz Castillo

6/24/2008 2:29:00 PM

0

El Martes, 24 de Junio de 2008, Guillermo.Acilu@koiaka.com 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-threadi...


> 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ñaki Baz Castillo

6/24/2008 3:10:00 PM

0

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

Zhukov Pavel

6/24/2008 3:26:00 PM

0

Y29yZSBhcHAgc3RhcnRzIERS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Baz Castillo

6/24/2008 3:30:00 PM

0

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/tru... #core class
> http://code.google.com/p/rudcpp/source/browse/trunk/plugins...
> #all plugins should be based on it
> http://code.google.com/p/rudcpp/source/browse/trunk/lib...
> #modified signal system

Thanks a lot, it seems interesting.



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

Charles Oliver Nutter

6/24/2008 10:08:00 PM

0

Guillermo.Acilu@koiaka.com wrote:
> 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