Re:EventMachine: scalable non-blocking i/o in ruby
by jrockway on Monday March 15, 2010 @06:22PM
(#1194304)
They can be automatically preempted if you desire, see: http://github.com/nothingmuch/coro/commit/54902809d8d3ad054d...
Usually people dismiss Coro because they want to take advantage of multiple cores without running multiple processes. But the reality is that you'll see a maximum 8x speedup if you run 8 OS threads, but if you rewrite your critical section in Haskell, you'll see a 50x speedup. So really , Coros are exactly the right abstraction for "scripting languages". IO performance is great, and expressiveness is great. Speed can be gained in other ways.
Re:EventMachine: scalable non-blocking i/o in ruby
by sreque on Monday March 15, 2010 @08:39PM
(#1194581)
I agree entirely about not needing threads in a scripting language like perl for CPU performance reasons, and being able to configure the threads to be scheduled automatically is a big win in my book. Thanks for letting me know about the library!
The way the Coro author implements Perl threads, by the way, sounds similar to how MacRuby and Rubinius are attempting to remove the GIL in ruby by copying interpreter state so that multiple OS threads can run simultaneously.
edit: after reading further, it turns out these threads are cooperative in that only one can run at a time. Also, it looks like they act more like Ruby fibers in that one must give up control explicitly or make a blocking call that implicitly gives up control. I'd rather the core scheduler be able to preempt threads directly. What if one of the threads takes a long time or ends up in an infinite loop?
"This module collection manages continuations in general, most often in the form of cooperative threads (also called coros, or simply "coro" in the documentation). They are similar to kernel threads but don't (in general) run in parallel at the same time even on SMP machines"