From: Charles Oliver Nutter Date: 2008-07-02T05:35:49+09:00 Subject: Re: Threads and Ruby I単aki Baz Castillo wrote: > Now I'm doing a server in Ruby using green threads (Ruby MRI). > In the future it's possible I try to migrate it to JRuby to use real threads. > > Just a question: Will my code and for now green threads work correctly under > JRuby and green threads will become OS threads magically? or must I change my > code to work with OS threads? You should not need to do anything and the threads will "just be native". We do that by hobbling native threads slightly so they check for those "unsafe" events like kill, raise, and critical. One down side to native threads is that launching a thread in JRuby is a lot more costly than in MRI, but we also have a thread pool (somewhat experimental, but people are using it) to mitigate that cost: Normal: user system total real control loop 0.005000 0.000000 0.005000 ( 0.006000) Thread.new.join loop 2.569000 0.000000 2.569000 ( 2.569000) -J-Djruby.thread.pool.enabled=true: user system total real control loop 0.009000 0.000000 0.009000 ( 0.009000) Thread.new.join loop 0.655000 0.000000 0.655000 ( 0.654000) This improves more with a longer run. - Charlie