SlideShare a Scribd company logo
1 of 28
Download to read offline
Fast, concurrent ruby
web applications with
EM and EM::Synchrony

        Kyle Drake
A bit about me.
• Full time Facebook developer
• All FB apps: Sinatra + DM, MRI + Thin on EY, Heroku
• Lots and lots of slow API calls to Facebook
• Lots and lots of delayed timeouts, API errors
• Lots and lots of users
• Lots and lots of performance issues from slow API
  calls!
MapAttack!
MapAttack!
• Over 60 hits per second
• Lots of network API calls to Geoloqi platform
• Lots of scary thread exceptions (Rainbows! +
  ThreadSpawn)
• Completely unsustainable as a conventional
  ruby web application
What’s going on here?
• Blocking IO!
• Process spends 90% of time waiting, 10% actually
  doing something
• Raw performance (Typheous vs Net::HTTP) is
  almost irrelevant! It’s not your bottleneck.
• MRI: No real threads, so IO blocks. 1.8 has green
  threads, 1.9 has kernel threads with GIL
• JRuby: Real kernel threads, much better. But slow
  (before JIT warms up), special deploy stack, and...
Based on the Reactor pattern..
        No threads (sortof)
       No blocking IO at all
      Uses callbacks as events
 var app = express.createServer();

 app.get('/', function(req, res){
     res.send('Hello World');
 });

 app.listen(3000);

Is this the future of web development?
CALLBACK HELL
var   useFile = function(filename,callback){
      posix.stat(filename).addCallback(function (stats) {
          posix.open(filename, process.O_RDONLY, 0666).addCallback(function (fd) {
              posix.read(fd, stats.size, 0).addCallback(function(contents){
                  callback(contents);
              });
          });
      });
};




                                  I found far worse examples, but
                                   they wouldn’t fit on this page.
New feature: Joyent Owns It
 “Any sort of use in commerce, such as promoting a
    Platform-as-a-Service or professional services
  offering by using the Node.js mark, does require a
              written license agreement.”
“If Joyent notifies you that your use of any trademark
      is detrimental to any Joyent trademarks or is
otherwise unacceptable, you must immediately cease
               using the marks, blah blah...”
What does Node.js do?
It uses the Reactor pattern.
       Can we copy it?

           YES!
The Reactor Pattern
   “The reactor design pattern is a concurrent
    programming pattern for handling service
   requests delivered concurrently to a service
   handler by one or more inputs” - Wikipedia
   What Node.js does: Takes your blocking IO
  operation, shoves it into its own kernel thread
behind the scenes, uses Unix kernel magic to make
    it rejoin the reactor queue when it’s ready.

             • Linux: epoll(4)
             • BSD: kqueue/kevent
• Blocking IO a UNIVERSAL problem
• All programming languages have trouble with it
• The Reactor pattern resolves it
• Most languages have the Reactor pattern!
• Blocking IO a UNIVERSAL problem
• All programming languages have trouble with it
• The Reactor pattern resolves it
• Most languages have the Reactor pattern!
      JavaScript                     Node.js

       Python                        Twisted

        Ruby            EventMachine (libem, C)

         Java                    JBoss_Netty
                   (wait, what? I thought Java had good threading..)

        PHP             None yet (perhaps ever)
EventMachine
       • Stable, fast, mature, works!
       • Production tested
       • Thin has EM built in
       • Hosting Support (CloudFoundry, Heroku)
# Source: http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers/

EventMachine.run {
  page = EventMachine::HttpRequest.new('http://google.ca/').get
  page.errback { p "Google is down! terminate?" }
  page.callback {
    about = EventMachine::HttpRequest.new('http://google.ca/search?q=eventmachine').get
    about.callback { # callback nesting, ad infinitum }
    about.errback { # error-handling code }
  }
}
EventMachine
                  The Bad
• Documentation is weak
• It’s weird for synchronous programmers
• Education problem - nobody understands it
• Like Node.js, it requires callback programming
• Callbacks don’t play nicely with web frameworks
  without nasty hacks (async-sinatra, throw :async,
  et cetera)
EventMachine
What if I told you you could do
 concurrent asynchronous
 programming, WITHOUT
         CALLBACKS?
EM-Synchrony
• http://github.com/igrigorik/em-synchrony
• “Collection of convenience classes and
  primitives to help untangle evented code,
  plus a number of patched EM clients to make
  them Fiber aware”
• Wraps callbacks in Ruby 1.9 Fibers
  automatically via EM::Synchrony.sync. The
  result: NO CALLBACKS!
• Anything with a callback method can be
  patched instantly to support this.
EM-Synchrony
def http_get(url)
  f = Fiber.current
  http = EventMachine::HttpRequest.new(url).get

 # resume fiber once http call is done
 http.callback { f.resume(http) }
 http.errback { f.resume(http) }

  return Fiber.yield
end

EventMachine.run do
  Fiber.new{
    page = http_get('http://www.google.com/')
    puts "Fetched page: #{page.response_header.status}"

    if page
      page = http_get('http://www.google.com/search?q=eventmachine')
      puts "Fetched page 2: #{page.response_header.status}"
    end
  }.resume
end
EM-Synchrony
EventMachine.synchrony do
  page = EventMachine::HttpRequest.new("http://www.google.com").get

  p "No callbacks! Fetched page: #{page}"
  EventMachine.stop
end
EM-Synchrony
                         Goliath
    http://postrank-labs.github.com/goliath
require 'goliath'

class Hello < Goliath::API
  # reload code on every request in dev environment
  use ::Rack::Reloader, 0 if Goliath.dev?

 def response(env)
  [200, {}, "Hello World"]
 end
end

# > ruby hello.rb -sv
# > [97570:INFO] 2011-02-15 00:33:51 :: Starting server on 0.0.0.0:9000
EM-Synchrony
                 Goliath
• Awesome! But...
• Designed for SOA work, not high-level web
  development
• Doesn’t play nicely with Rack, Thin, Heroku
• It’s re-inventing the wheel (I love Sinatra!)
• Can we make Sinatra work with EM-Synchrony?
                   YES!
Sinatra-Synchrony
        http://github.com/kyledrake/sinatra-synchrony

•   Tiny glue extension, < 100 LOC

•   Same old Sinatra, concurrency is (mostly) built in.

•   EventMachine and EM-Synchrony, Rack, Thin, Rainbows!,
    CloudFoundry, Heroku

•   Wraps each request in its own Fiber

•   Only coding change is to use non-blocking drivers/libraries

•   Patches Rack::Test to make tests run within EM-Synchrony fiber

            Wow, that was easy.
Conclusions
•   You can bake strong concurrency support into Ruby
    with almost zero changes to your code

•   You can take advantage of this while programming
    synchronously as usual.. Node.js can’t!

•   This makes Ruby a real competitor here. Strong
    performance, concurrency, maintainability, productivity,
    testing

•   RUBY IS NOT SLOW. This is a marketing failure, and
    we need to fix it.
What You Can Do
•   Try this stuff out! Play with it. Teach others how to use
    it. Work on the code for it.

•   Help me with this Sinatra-Synchrony idea. Perhaps we
    can make the idea more general purpose? Rails
    support?

•   DEFEND RUBY FROM THE “RUBY IS SLOW”
    PEOPLE. Sinatra-Synchrony gets 3000 hits per second
    in benchmarks on my MacBook with OSX’s crappy
    network stack, on one core. Productivity and
    performance are not incompatible here.

•   It’s my birthday today, get me drunk.
The Future
         Rubinius - Hydra Branch
       http://rubini.us/2011/02/17/rubinius-what-s-next

• The Smalltalk-80 Blue Book approach is working
• They are trashing their GIL with pure ruby!
• Supports EventMachine, Fibers coming soon
• Because of Evan (and friends), Alan Kay, Ezra,
    RUBINIUS IS THE FUTURE
Thank you.
Questions?

More Related Content

What's hot

Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJSJITENDRA KUMAR PATEL
 
Online game server on Akka.NET (NDC2016)
Online game server on Akka.NET (NDC2016)Online game server on Akka.NET (NDC2016)
Online game server on Akka.NET (NDC2016)Esun Kim
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksThomas Fuchs
 
Asterisk, HTML5 and NodeJS; a world of endless possibilities
Asterisk, HTML5 and NodeJS; a world of endless possibilitiesAsterisk, HTML5 and NodeJS; a world of endless possibilities
Asterisk, HTML5 and NodeJS; a world of endless possibilitiesDan Jenkins
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in LispVladimir Sedach
 
My month with Ruby
My month with RubyMy month with Ruby
My month with Rubyalextomovski
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerGeorge Miranda
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itRyan Weaver
 

What's hot (20)

Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
Online game server on Akka.NET (NDC2016)
Online game server on Akka.NET (NDC2016)Online game server on Akka.NET (NDC2016)
Online game server on Akka.NET (NDC2016)
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
 
Asterisk, HTML5 and NodeJS; a world of endless possibilities
Asterisk, HTML5 and NodeJS; a world of endless possibilitiesAsterisk, HTML5 and NodeJS; a world of endless possibilities
Asterisk, HTML5 and NodeJS; a world of endless possibilities
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
About Clack
About ClackAbout Clack
About Clack
 
Developing high-performance network servers in Lisp
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in Lisp
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
My month with Ruby
My month with RubyMy month with Ruby
My month with Ruby
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love itDrupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
 
Queue your work
Queue your workQueue your work
Queue your work
 
JavaScript Web Workers
JavaScript Web WorkersJavaScript Web Workers
JavaScript Web Workers
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 

Similar to Fast, concurrent ruby web applications with EventMachine and EM::Synchrony

Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?hawkowl
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009pratiknaik
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0Jan Sifra
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
The JavaScript Delusion
The JavaScript DelusionThe JavaScript Delusion
The JavaScript DelusionJUGBD
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Tech Thursdays: Building Products
Tech Thursdays: Building ProductsTech Thursdays: Building Products
Tech Thursdays: Building ProductsHayden Bleasel
 

Similar to Fast, concurrent ruby web applications with EventMachine and EM::Synchrony (20)

Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Node azure
Node azureNode azure
Node azure
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
The JavaScript Delusion
The JavaScript DelusionThe JavaScript Delusion
The JavaScript Delusion
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Tech Thursdays: Building Products
Tech Thursdays: Building ProductsTech Thursdays: Building Products
Tech Thursdays: Building Products
 

Fast, concurrent ruby web applications with EventMachine and EM::Synchrony

  • 1. Fast, concurrent ruby web applications with EM and EM::Synchrony Kyle Drake
  • 2. A bit about me. • Full time Facebook developer • All FB apps: Sinatra + DM, MRI + Thin on EY, Heroku • Lots and lots of slow API calls to Facebook • Lots and lots of delayed timeouts, API errors • Lots and lots of users • Lots and lots of performance issues from slow API calls!
  • 4. MapAttack! • Over 60 hits per second • Lots of network API calls to Geoloqi platform • Lots of scary thread exceptions (Rainbows! + ThreadSpawn) • Completely unsustainable as a conventional ruby web application
  • 5. What’s going on here? • Blocking IO! • Process spends 90% of time waiting, 10% actually doing something • Raw performance (Typheous vs Net::HTTP) is almost irrelevant! It’s not your bottleneck. • MRI: No real threads, so IO blocks. 1.8 has green threads, 1.9 has kernel threads with GIL • JRuby: Real kernel threads, much better. But slow (before JIT warms up), special deploy stack, and...
  • 6.
  • 7.
  • 8. Based on the Reactor pattern.. No threads (sortof) No blocking IO at all Uses callbacks as events var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.listen(3000); Is this the future of web development?
  • 9. CALLBACK HELL var useFile = function(filename,callback){     posix.stat(filename).addCallback(function (stats) {         posix.open(filename, process.O_RDONLY, 0666).addCallback(function (fd) {             posix.read(fd, stats.size, 0).addCallback(function(contents){                 callback(contents);             });         });     }); }; I found far worse examples, but they wouldn’t fit on this page.
  • 10. New feature: Joyent Owns It “Any sort of use in commerce, such as promoting a Platform-as-a-Service or professional services offering by using the Node.js mark, does require a written license agreement.” “If Joyent notifies you that your use of any trademark is detrimental to any Joyent trademarks or is otherwise unacceptable, you must immediately cease using the marks, blah blah...”
  • 11.
  • 12. What does Node.js do? It uses the Reactor pattern. Can we copy it? YES!
  • 13. The Reactor Pattern “The reactor design pattern is a concurrent programming pattern for handling service requests delivered concurrently to a service handler by one or more inputs” - Wikipedia What Node.js does: Takes your blocking IO operation, shoves it into its own kernel thread behind the scenes, uses Unix kernel magic to make it rejoin the reactor queue when it’s ready. • Linux: epoll(4) • BSD: kqueue/kevent
  • 14. • Blocking IO a UNIVERSAL problem • All programming languages have trouble with it • The Reactor pattern resolves it • Most languages have the Reactor pattern!
  • 15. • Blocking IO a UNIVERSAL problem • All programming languages have trouble with it • The Reactor pattern resolves it • Most languages have the Reactor pattern! JavaScript Node.js Python Twisted Ruby EventMachine (libem, C) Java JBoss_Netty (wait, what? I thought Java had good threading..) PHP None yet (perhaps ever)
  • 16. EventMachine • Stable, fast, mature, works! • Production tested • Thin has EM built in • Hosting Support (CloudFoundry, Heroku) # Source: http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers/ EventMachine.run { page = EventMachine::HttpRequest.new('http://google.ca/').get page.errback { p "Google is down! terminate?" } page.callback { about = EventMachine::HttpRequest.new('http://google.ca/search?q=eventmachine').get about.callback { # callback nesting, ad infinitum } about.errback { # error-handling code } } }
  • 17. EventMachine The Bad • Documentation is weak • It’s weird for synchronous programmers • Education problem - nobody understands it • Like Node.js, it requires callback programming • Callbacks don’t play nicely with web frameworks without nasty hacks (async-sinatra, throw :async, et cetera)
  • 18. EventMachine What if I told you you could do concurrent asynchronous programming, WITHOUT CALLBACKS?
  • 19. EM-Synchrony • http://github.com/igrigorik/em-synchrony • “Collection of convenience classes and primitives to help untangle evented code, plus a number of patched EM clients to make them Fiber aware” • Wraps callbacks in Ruby 1.9 Fibers automatically via EM::Synchrony.sync. The result: NO CALLBACKS! • Anything with a callback method can be patched instantly to support this.
  • 20. EM-Synchrony def http_get(url) f = Fiber.current http = EventMachine::HttpRequest.new(url).get # resume fiber once http call is done http.callback { f.resume(http) } http.errback { f.resume(http) } return Fiber.yield end EventMachine.run do Fiber.new{ page = http_get('http://www.google.com/') puts "Fetched page: #{page.response_header.status}" if page page = http_get('http://www.google.com/search?q=eventmachine') puts "Fetched page 2: #{page.response_header.status}" end }.resume end
  • 21. EM-Synchrony EventMachine.synchrony do page = EventMachine::HttpRequest.new("http://www.google.com").get p "No callbacks! Fetched page: #{page}" EventMachine.stop end
  • 22. EM-Synchrony Goliath http://postrank-labs.github.com/goliath require 'goliath' class Hello < Goliath::API # reload code on every request in dev environment use ::Rack::Reloader, 0 if Goliath.dev? def response(env) [200, {}, "Hello World"] end end # > ruby hello.rb -sv # > [97570:INFO] 2011-02-15 00:33:51 :: Starting server on 0.0.0.0:9000
  • 23. EM-Synchrony Goliath • Awesome! But... • Designed for SOA work, not high-level web development • Doesn’t play nicely with Rack, Thin, Heroku • It’s re-inventing the wheel (I love Sinatra!) • Can we make Sinatra work with EM-Synchrony? YES!
  • 24. Sinatra-Synchrony http://github.com/kyledrake/sinatra-synchrony • Tiny glue extension, < 100 LOC • Same old Sinatra, concurrency is (mostly) built in. • EventMachine and EM-Synchrony, Rack, Thin, Rainbows!, CloudFoundry, Heroku • Wraps each request in its own Fiber • Only coding change is to use non-blocking drivers/libraries • Patches Rack::Test to make tests run within EM-Synchrony fiber Wow, that was easy.
  • 25. Conclusions • You can bake strong concurrency support into Ruby with almost zero changes to your code • You can take advantage of this while programming synchronously as usual.. Node.js can’t! • This makes Ruby a real competitor here. Strong performance, concurrency, maintainability, productivity, testing • RUBY IS NOT SLOW. This is a marketing failure, and we need to fix it.
  • 26. What You Can Do • Try this stuff out! Play with it. Teach others how to use it. Work on the code for it. • Help me with this Sinatra-Synchrony idea. Perhaps we can make the idea more general purpose? Rails support? • DEFEND RUBY FROM THE “RUBY IS SLOW” PEOPLE. Sinatra-Synchrony gets 3000 hits per second in benchmarks on my MacBook with OSX’s crappy network stack, on one core. Productivity and performance are not incompatible here. • It’s my birthday today, get me drunk.
  • 27. The Future Rubinius - Hydra Branch http://rubini.us/2011/02/17/rubinius-what-s-next • The Smalltalk-80 Blue Book approach is working • They are trashing their GIL with pure ruby! • Supports EventMachine, Fibers coming soon • Because of Evan (and friends), Alan Kay, Ezra, RUBINIUS IS THE FUTURE

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n