You are on page 1of 7

Ruby Fibers

Aidan Feldman
Thread Types
Red Green
 Run at OS level  Run inside the VM

 CPU time+  Small overhead

 HARD  Cooperative scheduling


a) Two execution threads; one thread blocks for 40ms on
Fibers vs. Theads an IO call and then takes 10ms to post-process the data;
second thread needs 50ms of pure CPU time
(blocking) b) Same scenario implemented with Fibers and
cooperative scheduling
Event-Driven Programming
 Reactor pattern
 Event loop sends to request handlers
 i.e. Python’s Twisted, Eventmachine, Node.js

 Nested callbacks
Async as Sync
Use Cases
Red Green
 Computationally-  Blocking requests
expensive tasks  Filesystem IO
 Sorting  Network IO
 Map-reduce
Resources
 igvita.com

 EM-Synchrony

You might also like