• Share
  • Email
  • Embed
  • Like
  • Private Content
High Performance Ruby: Evented vs. Threaded
 

High Performance Ruby: Evented vs. Threaded

on

  • 2,901 views

Dr Nic Williams' Ruby Midwest 2011 presentation ...

Dr Nic Williams' Ruby Midwest 2011 presentation

Presentation description:
I wanted to know, "Do I need to learn about EventMachine or node.js? Can I use threads? What is so good or bad about threading in Ruby 1.8, Ruby 1.9, JRuby and Rubinius 2.0?"
What was important to me was that the choice was abstracted away. I wanted to write normal, step-by-step Ruby code. Yet I wanted it to be performant.
I've asked a lot of people. I even hosted EventMachine RubyConf (http://emrubyconf.com) during RailsConf 2011 in order to gather the brightest minds in the Ruby community. "What choices do I need to make, how different does my code look, and how do I do testing?" These are the questions I searched for answers to. I'd like to now share the answers.

Statistics

Views

Total Views
2,901
Views on SlideShare
2,901
Embed Views
0

Actions

Likes
1
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    High Performance Ruby: Evented vs. Threaded High Performance Ruby: Evented vs. Threaded Presentation Transcript

    • High-Performance Ruby: Evented vs readed Dr Nic Williams @drnic | drnicwilliams.com | engineyard.com
    • “rubymidwest”
    • “rubymidwest”
    • midwest
    • midwest
    • kansas
    • kansas city
    • in Missouri
    • midwest?!
    • an actual safari
    •  ________  <  Safari  >  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                        ^__^                      (xx)_______                        (__)              )/                          ^    ||-­‐-­‐-­‐-­‐w  |                                ||          ||
    • drniccowsay
    • You have $
    • New project/rapid dev(features/$) Optimise (bugs/$) (req thru-put/$) (req latency/$)
    • Add resources
    • Resources = $ $
    • or even $$$$$ $ $ $$$
    • New project/rapid dev(features/$) how? (performance/$0) Optimise
    • Options•Add resources•Use resources better
    • you?just write code
    • evented -> threads-> your code
    • nginx-> trinidad-> web app
    • evented? arrange I/O
    • threads? actual work
    • you?just write code
    • evented -> threads-> your code
    • nginx-> trinidad-> web app
    • Options•Add resources•Use resources better
    • Concurrency•process concurrency•threaded concurrency•evented concurrency
    • Process vsreaded
    • Process Concurrency•1 req = 1 process = 150Mb•“100 reqs?” = 15Gb!•Orchestrated by? Kernel•Unicorn, Passenger
    • readed Concurrency•1 req = 1 thread = 2kb•“100 reqs?”=150Mb+200kb•Orchestrated by? Kernel•Mongrel*
    • 1 req =1 thread = 2kb
    • Process vsreaded
    • evented -> threads-> your code
    • readed Concurrency•....•....•....•Mongrel*
    • readed Concurrency•....•....•....•Mongrel*
    • “Mongrel isthreaded?!”
    • 2006 reality:Mongrel * Rails * Ruby1.8 -->process conc.
    • 20068 reality:“Rails 2.2... rst...threadsafe Rails” --Pratik Naik
    • 20068 reality:config.threadsafe! http://guides.rubyonrails.org/configuring.html
    • 20068 reality:# do nothing http://www.sinatrarb.com/configuration.html
    • 20068 reality:Mongrel * Rails * Ruby1.8 --> process conc.
    • 200810 reality:“Ruby 1.9.2 is released”
    • 200810 reality:1.9 has native threads!
    • 200810 reality:1 thread of Ruby at a time :(
    • 200810 reality:GIL = GlobalInterpreter Lock :(
    • 200810 reality: GIL:(“Grumpy Gil”
    • 200810 reality:Mongrel * Rails * Ruby1.9 -->process conc.
    • “Mongrel is threaded?!” “Rails is threadsafe”but no threads...
    • “readsplease!”
    • rvm install jrubyrvm use jrubygem install railsrails new myapp
    • gem activerecord- jdbcsqlite3- adaptergem jruby-openssl
    • Mongrel * Rails * JRuby --> thread concurrency!
    • 1 req =1 thread = 2kb
    • “How do Irun JRuby/ Rails?”
    • How?-> trinidad -> web app
    • $ gem install trinidad$ trinidad--> localhost:3000
    • $ git clone git:// github.com/ engineyard/todo.git$ cd todo$ bundle$ rake db:migrate$ trinidad
    • # config.threadsafe!$ trinidadInfo: max runtimes = 5
    • config.threadsafe! # yes!$ trinidad -e productionInfo: max runtimes = 1(Thread limit 200)
    • 1 req =1 thread = 2kb
    • And its justnormal web app code!
    • evented -> threads-> your code
    • nginx-> trinidad-> web app
    • “I’m scaredof threads”
    • Web apps are*thread safe
    • Dr Nic’s Joy of Concurrency“Store state elsewhere;Unless its safe”
    • evented -> threads-> your code
    • nginx-> trinidad-> web app
    • “I came to hear good things aboutEventMachine”
    • “Evented is cool,threads are not”
    • “You haven’tsaid ‘nodejs’ once!?”
    • What isevented? any do somethingI/O? with it
    • cache hitsreq ? cache web miss app
    • cache hitsreq ? cache web miss app
    • req I/O work
    • req I/O work evented threads
    • req I/O work evented threads nginx trinidad
    • nginxvs apache
    • “Hosted?”500 hrs free!
    • Come work with us!jruby coretrinidad corerubinius core
    • “Be a happy developer”-> your code
    • -> threads-> your code
    • evented -> threads-> your code
    • nginx-> trinidad-> web app@drnic | drnicwilliams.com | engineyard.com
    •  _____________  <  Power  Ruby!  >  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐                        ^__^                      (Oo)_______                        (__)              )/                          <>  ||-­‐-­‐-­‐-­‐w  |                                ||          || @drnic | drnicwilliams.com | engineyard.com