rev, revactor, reia - fails.orgfails.org/rev_revactor_reia.pdf · cool.io: like eventmachine but...
TRANSCRIPT
![Page 1: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/1.jpg)
Rev, Revactor, ReiaOr, the journey to Reia
![Page 2: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/2.jpg)
Tony Arcieri@bascule
![Page 3: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/3.jpg)
![Page 4: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/4.jpg)
Rev, Revactor,
ReiaRedundant
![Page 5: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/5.jpg)
Rev: Ruby event framework
http://github.com/tarcieri/rev
![Page 6: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/6.jpg)
Cool.io
More on this later...
![Page 7: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/7.jpg)
I love network programming
![Page 8: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/8.jpg)
Application
Web Framework
Rack
Web ServerOMFG network craziness!
Ruby VMOMFG compilers and VMs break my brain!
OS KernelHere Be Dragons
![Page 9: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/9.jpg)
There is life outside of HTTP
![Page 10: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/10.jpg)
2003
![Page 11: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/11.jpg)
http://github.com/tarcieri/distribustream
![Page 12: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/12.jpg)
BitTorrent but better
•Started writing a BitTorrent library in C, FOR SPEED!
•BitTorrent sucks, I can do it better
•Spent 2 years trying to develop a new protocol in C
![Page 13: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/13.jpg)
2005
![Page 14: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/14.jpg)
I’m not productive!
•I’d like to write things in a scripting language instead of C
•Ruby’s cool, but it’s not FOR SPEED
•Maybe YARV will be FOR SPEED
•OMFG RAILS!!! I can get a job with that!
![Page 15: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/15.jpg)
2006
![Page 16: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/16.jpg)
DistribuStream inRuby
•Written in Ruby instead of Python
•Using EventMachine to handle large numbers of connections
•Use central organization and collaborative filtering to organize the peer network
![Page 17: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/17.jpg)
Rails has Problems
•CGI sucks
•FCGI sucks (who remembers lighttpd?)
•SCGI sucks
•Apache Coyote for Ruby??
![Page 18: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/18.jpg)
OMG MONGREL!
![Page 19: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/19.jpg)
RubyConf 2006
![Page 20: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/20.jpg)
RubyConf 2006
•Slept through Evan Phoenix’s keynote
•Waited for Matz’s announcement that YARV would be released on Christmas
•Where’s YARV on Christmas?
![Page 21: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/21.jpg)
YARV
![Page 22: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/22.jpg)
NO YARV FOR YOU!
:(
![Page 23: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/23.jpg)
That made me a sad panda...
but there was an open bar :D
![Page 24: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/24.jpg)
Ask Matz a question!
ME: WHERE’S YARV?!#$!$#!$
![Page 25: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/25.jpg)
I met this guy...
![Page 26: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/26.jpg)
![Page 27: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/27.jpg)
Earlier that day...
![Page 28: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/28.jpg)
“I’m Zed Shaw and I wrote Mongrel”
THUNDEROUS APPLAUSE
![Page 29: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/29.jpg)
Zed and I
•OMG why don’t people care about that sort of thing?
•CGI Multipart EOF Bug OMG!
•Zed: EventMachine sucks. You should work on Ruby/Event
![Page 30: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/30.jpg)
Meanwhile...
![Page 31: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/31.jpg)
Denver Accord
•Matz, ko1, _why, et al talked for 4 hours on the Sunday night after RubyConf 2006
•Create NEW repo for 1.9
•Prohibit commits to MATZ
•Merge YARV into NEW
![Page 32: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/32.jpg)
2007
![Page 33: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/33.jpg)
EventMachine
•I became a committer
•I tried to fix as many problems as I could
•I eventually succumbed to too many OMFGs/sec
![Page 34: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/34.jpg)
Rev
•Started by Franki Rai and Zed
•A Ruby wrapper for the libev library
•Both of them soon left, leaving me as the principal author
![Page 35: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/35.jpg)
"The best way to complain is to make things." - James Murphy
![Page 36: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/36.jpg)
Zed wanted a new blog theme...
so I introduced him to our designer
![Page 37: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/37.jpg)
![Page 38: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/38.jpg)
Zed’s exit
![Page 39: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/39.jpg)
Cool.io: Ruby event framework
http://github.com/tarcieri/cool.io
![Page 40: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/40.jpg)
Use Cases
• Large numbers of connections• Large amounts of I/O• Shared state between connections
![Page 41: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/41.jpg)
Example Applications
• Web Spiders• HTTP Push Servers• Chat Servers
![Page 42: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/42.jpg)
Supported Platforms
• Ruby MRI (1.8.6+)• Ruby YARV (1.9.0+)• Rubinius HEAD
![Page 43: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/43.jpg)
Evented Programming Crash Course
Instead of:
response = request.get(params)
do:
request.start(params)
def on_success(response); ...; enddef on_failure(response); ... end
![Page 44: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/44.jpg)
Block Form
start_request(params) do |response|if response.success?...YAY...
else...BOO...
endend
![Page 45: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/45.jpg)
Cool.io: like EventMachine but with Ruby I/O primitives
![Page 46: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/46.jpg)
Cool.io concepts
•Cool.io::Loop is the core event loop and the only thing that blocks EVAR
•Attach event listeners to it
![Page 47: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/47.jpg)
Echo Server Example
![Page 48: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/48.jpg)
require 'rubygems'require 'cool.io'
ADDR = '127.0.0.1'PORT = 4321
class EchoServerConnection < Cool.io::TCPSocket def on_connect puts "#{remote_addr}:#{remote_port} connected" end
def on_close puts "#{remote_addr}:#{remote_port} disconnected" end
def on_read(data) write data endend
event_loop = Cool.io::Loop.defaultCool.io::TCPServer.new(ADDR, PORT, EchoServerConnection).attach(event_loop)
puts "Echo server listening on #{ADDR}:#{PORT}"event_loop.run
![Page 49: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/49.jpg)
HTTP Client Example
![Page 50: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/50.jpg)
require 'rubygems'require 'cool.io'
class MyHttpClient < Cool.io::HttpClient def on_connect super STDERR.puts "Connected to #{remote_host}:#{remote_port}" end
def on_connect_failed super STDERR.puts "Connection failed" end
def on_response_header(header) STDERR.puts "Response: #{header.http_version} #{header.status} #{header.http_reason}" end
def on_body_data(data) STDOUT.write data STDOUT.flush end
def on_request_complete STDERR.puts "Request complete!" end
def on_error(reason) STDERR.puts "Error: #{reason}" endend
loop = Cool.io::Loop.defaultclient = MyHttpClient.connect("www.google.com", 80).attach(l)client.request('GET', '/search', :query => { :q => 'foobar' })loop.run
![Page 51: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/51.jpg)
It's got filesystem monitoring!
Watchr uses it
![Page 52: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/52.jpg)
Ry wrote a web server called Ebb
•Based on libev
•Ry showed me better ways Rev could work with Ruby 1.8’s scheduler
•Ry would later adapt Ebb into Node.js
![Page 53: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/53.jpg)
Next steps: - async file I/O (libeio, like Node) https://github.com/tarcieri/cool.io/tree/libeio
- libevent support ($50 bounty!)
![Page 54: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/54.jpg)
OMG ERLANG!
![Page 55: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/55.jpg)
![Page 56: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/56.jpg)
Erlang seemed REALLY awesome
![Page 57: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/57.jpg)
Please cover your ears if you are sensitive to
loud noises
![Page 58: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/58.jpg)
![Page 59: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/59.jpg)
My “dream” model
•Evented I/O loop
•One scheduler thread per CPU core
•Lightweight userspace processes that talked using messages
![Page 60: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/60.jpg)
Erlang did this OVER 9000 times better than I ever
could have
![Page 61: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/61.jpg)
I took the ideas of Erlang and started
working on Revactoron Ruby 1.9 Fibers
![Page 62: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/62.jpg)
Christmas:YARV released!
I’m a happy panda
![Page 63: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/63.jpg)
2008
![Page 64: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/64.jpg)
January 2008: Revactor released
![Page 65: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/65.jpg)
Revactor: Actors for 1.9
http://github.com/tarcieri/revactor
![Page 66: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/66.jpg)
My boss said I couldn't use Erlang :(
Fuck it, do it in Ruby!
![Page 67: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/67.jpg)
Combine Rev Cool.io + Fibers to get callback-free async
programming!
Later seen in NeverBlock and em-synchrony
![Page 68: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/68.jpg)
Evented Programming Crash Course
Instead of:
response = request.get(params)
do:
request.start(params)
def on_success(response); ...; enddef on_failure(response); ... end
THIS SUCKS
![Page 69: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/69.jpg)
Block Form
start_request(params) do |response|if response.success?...YAY...
else...BOO...
endend
THIS SUCKS
![Page 70: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/70.jpg)
Evented Programming smells like...
•Callback soup
•Callback spaghetti
•Callback HELL
![Page 71: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/71.jpg)
Revactor was the first and still the most comprehensive solution for Fibers+events
•NeverBlock and em-synchrony merely wrap events in synchronous APIs
•Revactor uses messages to let fibers communicate
![Page 72: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/72.jpg)
Echo Server Example
![Page 73: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/73.jpg)
# An example echo server, written using Revactor::TCP# This implementation creates a new actor for each# incoming connection.
require 'revactor'
HOST = 'localhost'PORT = 4321
# Create a new listener socket on the given host and portlistener = Revactor::TCP.listen(HOST, PORT)puts "Listening on #{HOST}:#{PORT}"
# Begin receiving connectionsloop do # Accept an incoming connection and start a new Actor # to handle it Actor.spawn(listener.accept) do |sock| puts "#{sock.remote_addr}:#{sock.remote_port} connected"
# Begin echoing received data loop do begin # Write everything we read sock.write sock.read rescue EOFError puts "#{sock.remote_addr}:#{sock.remote_port} disconnected"
# Break (and exit the current actor) if the connection # is closed, just like with a normal Ruby socket break end end endend
![Page 74: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/74.jpg)
Async web apps with Rainbows!Unicorn for asynchronous backends
http://rainbows.rubyforge.org/
![Page 75: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/75.jpg)
Rainbows! do use :Revend
Rainbows! do use :Revactorend
(That’s all I got, sorry)
![Page 76: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/76.jpg)
Acting the Actor Model
![Page 77: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/77.jpg)
Want to know more about Actors?
http://revactor.org/
![Page 78: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/78.jpg)
I became disenchanted with fake synchronous
I/O on top of Fibers
![Page 79: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/79.jpg)
Why?
![Page 80: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/80.jpg)
![Page 81: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/81.jpg)
Evented programming in Ruby is not POLS
Threads are
If you want evented programming, try Node.js
![Page 82: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/82.jpg)
Erlang fizzled
![Page 83: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/83.jpg)
People keep asking me, “What will happen to Erlang? Will it be a popular language?” I don’t
know. I think it’s already been influential. It might end up like Smalltalk. I think Smalltalk’s been
very, very influential and loved by an enthusiastic band of people but never really very widely
adopted. And I think Erlang might be like that.
-- Joe Armstrong, Coders at Work
![Page 84: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/84.jpg)
“It might need Microsoft to take some of its ideas and put curly braces here and there”
Or it might just need Ruby syntax... :)
![Page 85: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/85.jpg)
Zed got me interested in making my own languageand Erlang had horrible syntax
![Page 86: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/86.jpg)
http://github.com/tarcieri/reia
![Page 87: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/87.jpg)
I started Reia in 2008
![Page 88: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/88.jpg)
Erlang’s strengths:•Nonstop systems (99.999over9000%
uptime OMFG!)
•Realtime systems
•Fault-tolerant systems
•Hot code swapping
•Concurrent systems
•Distributed systems
![Page 89: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/89.jpg)
Erlang with Ruby syntax
![Page 90: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/90.jpg)
Immutable State
![Page 91: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/91.jpg)
OBLIGATORY GAGA
![Page 92: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/92.jpg)
2009
![Page 93: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/93.jpg)
Reia @ Erlang Factory
•Mostly working implementation!
•Concurrent object model based on Erlang/OTP gen_servers
•Web framework: Ryan
![Page 94: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/94.jpg)
I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages, so messaging came at the very beginning. It took a while to see how to do messaging in a programming language efficiently enough to be useful.
-- Alan Kay, creator of Smalltalk
![Page 95: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/95.jpg)
Meanwhile...
![Page 96: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/96.jpg)
Node.js got people interested in event-driven programming
![Page 97: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/97.jpg)
Node and Cool.io share technologies
Cool.io: libev+Ruby(+libeio)Node: libev+libeio+V8
![Page 98: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/98.jpg)
Late 2009
•REIA ZOMG TOO SLOW!!!
•Everything’s fucked! I didn’t know what I was doing
•If you fuck up a language project and don’t rewrite it, you get PHP
![Page 99: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/99.jpg)
2010
![Page 100: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/100.jpg)
Reia rewrite
•ZOMG OVER 9000x FASTER!
•Clean Erlang codebase which isn’t impossible to workwith
•Use concepts from the Erlang compiler
•Everything-is-an-object (although no concurrent objetcts yet, coming soon!)
![Page 101: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/101.jpg)
Let’s look at Reia!
![Page 102: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/102.jpg)
Ilya Grigorik created em-synchrony
![Page 103: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/103.jpg)
People are now actually interested in fake
synchronous programming on an
evented backend
![Page 104: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/104.jpg)
I think em-synchrony is aimed at
ROFLSCALING
![Page 105: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/105.jpg)
BUT... I dusted off Cool.io and Revactor
just in case you’re interested
![Page 106: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/106.jpg)
I still like Reia better :)
![Page 107: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/107.jpg)
Reia has had horrible
documentation...
![Page 108: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/108.jpg)
New web site!http://reia-lang.org/
Inspired by CoffeeScript
![Page 109: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/109.jpg)
Reia PEG Grammar
•https://github.com/graeme-defty/reia
•Built on Neotoma: Treetop for Erlang
•Written by Graeme Defty and Kim Shrier
•It has TESTS OMG!
![Page 110: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/110.jpg)
Why PEG is better
•Whitespace handling
•Nested interpolated strings e.g. (“foo #{“bar #{“baz”}”}”)
•Regex literals ala /.../
![Page 111: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/111.jpg)
Reia next steps:
•Singleton classes
•Concurrent objects
•Namespaces
•Default and keyword arguments
•Metaprogramming
![Page 112: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/112.jpg)
One more thing...
![Page 113: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/113.jpg)
COMPILERS AREN’T HARD
![Page 114: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/114.jpg)
Create Your Own Freaking Awesome
Programming Language
![Page 115: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/115.jpg)
If I can do it you can to...
![Page 116: Rev, Revactor, Reia - fails.orgfails.org/rev_revactor_reia.pdf · Cool.io: like EventMachine but with Ruby I/O primitives. Cool.io concepts](https://reader033.vdocument.in/reader033/viewer/2022050220/5f655e45971ca208f2755630/html5/thumbnails/116.jpg)
Links
• Cool.io: http://github.com/tarcieri/cool.io• Revactor: http://github.com/tarcieri/revactor• Reia: http://github.com/tarcieri/reia• Twitter: http://twitter.com/bascule• Blog: http://unlimitednovelty.com