SlideShare a Scribd company logo
High-Performance Ruby:
  Evented vs readed

          Dr Nic Williams



 @drnic | drnicwilliams.com | engineyard.com
“ruby
midwest”
“ruby
midwest”
midwest
midwest
kansas
kansas city
in Missouri
midwest?!
an actual
 safari
 ________	
  
<	
  Safari	
  >
	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ^__^
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (xx)_______
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (__)	
  	
  	
  	
  	
  	
  	
  )/
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ^	
  	
  ||-­‐-­‐-­‐-­‐w	
  |
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ||	
  	
  	
  	
  	
  ||
drnic

cowsay
High Performance Ruby: Evented vs. Threaded
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
High Performance Ruby: Evented vs. Threaded
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
High Performance Ruby: Evented vs. Threaded
readed
 Concurrency
•....
•....
•....
•Mongrel*
readed
 Concurrency
•....
•....
•....
•Mongrel*
“Mongrel is
threaded?!”
High Performance Ruby: Evented vs. Threaded
2006 reality:

Mongrel * Rails *
 Ruby1.8 -->
process conc.
20068 reality:
“Rails 2.2...
 rst...thread
safe 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 = Global
Interpreter
  Lock :(
200810 reality:

    GIL:(
“Grumpy Gil”
200810 reality:

Mongrel * Rails *
 Ruby1.9 -->
process conc.
“Mongrel is
  threaded?!”
    “Rails is
  threadsafe”
but no threads...
High Performance Ruby: Evented vs. Threaded
“reads
please!”
rvm install jruby
rvm use jruby
gem install rails
rails new myapp
gem 'activerecord-
       jdbcsqlite3-
          adapter'
gem 'jruby-openssl'
Mongrel * Rails *
   JRuby -->
    thread
 concurrency!
1 req =
1 thread =
    2kb
“How do I
run 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!

$ trinidad
Info: max runtimes = 5
config.threadsafe! # yes!

$ trinidad -e production
Info: max runtimes = 1
(Thread limit 200)
1 req =
1 thread =
    2kb
And its just
normal web
 app code!
evented
 -> threads
-> your code
nginx
-> trinidad
-> web app
“I’m scared
of threads”
Web apps
   are*
thread safe
Dr Nic’s Joy of
 Concurrency
“Store state elsewhere;
Unless its safe”
High Performance Ruby: Evented vs. Threaded
evented
 -> threads
-> your code
nginx
-> trinidad
-> web app
“I came to hear
  good things
     about
EventMachine”
“Evented is cool,
threads are not”
“You haven’t
said ‘nodejs’
  once!?”
What is
evented?
 any   do something
I/O?       with it
cache
     hits
req   ?
    cache   web
    miss    app
cache
     hits
req   ?
    cache   web
    miss    app
req   I/O   work
req    I/O      work
      evented   threads
req    I/O      work
      evented   threads
       nginx    trinidad
nginx
vs apache
“Hosted?”


500 hrs free!
Come work
   with us!
jruby core
trinidad core
rubinius 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

More Related Content

What's hot (19)

ODP
Integrating icinga2 and the HashiCorp suite
Bram Vogelaar
 
KEY
About Data::ObjectDriver
Yoshiki Kurihara
 
PDF
Lightweight wrapper for Hive on Amazon EMR
Shinji Tanaka
 
PDF
How to build a High Performance PSGI/Plack Server
Masahiro Nagano
 
PDF
Event Driven Architecture Concepts in Web Technologies - Part 1
Hamidreza Soleimani
 
PDF
AnyMQ, Hippie, and the real-time web
clkao
 
PPT
Triple Blitz Strike
Denis Zhdanov
 
PDF
Observability with Consul Connect
Bram Vogelaar
 
PDF
Rapid Infrastructure Provisioning
Uchit Vyas ☁
 
KEY
Mysqlnd uh
natmchugh
 
PDF
Intro to Scala.js - Scala UG Cologne
Marius Soutier
 
PDF
Hacking ansible
bcoca
 
PDF
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
ODP
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bram Vogelaar
 
PDF
Infrastructure as code terraformujeme cloud
ViliamPucik
 
PDF
DBD::Gofer 200809
Tim Bunce
 
KEY
MongoFr : MongoDB as a log Collector
Pierre Baillet
 
PDF
Intro to sbt-web
Marius Soutier
 
PDF
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Masahiro Nagano
 
Integrating icinga2 and the HashiCorp suite
Bram Vogelaar
 
About Data::ObjectDriver
Yoshiki Kurihara
 
Lightweight wrapper for Hive on Amazon EMR
Shinji Tanaka
 
How to build a High Performance PSGI/Plack Server
Masahiro Nagano
 
Event Driven Architecture Concepts in Web Technologies - Part 1
Hamidreza Soleimani
 
AnyMQ, Hippie, and the real-time web
clkao
 
Triple Blitz Strike
Denis Zhdanov
 
Observability with Consul Connect
Bram Vogelaar
 
Rapid Infrastructure Provisioning
Uchit Vyas ☁
 
Mysqlnd uh
natmchugh
 
Intro to Scala.js - Scala UG Cologne
Marius Soutier
 
Hacking ansible
bcoca
 
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bram Vogelaar
 
Infrastructure as code terraformujeme cloud
ViliamPucik
 
DBD::Gofer 200809
Tim Bunce
 
MongoFr : MongoDB as a log Collector
Pierre Baillet
 
Intro to sbt-web
Marius Soutier
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Masahiro Nagano
 

Similar to High Performance Ruby: Evented vs. Threaded (20)

PPTX
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
PDF
Lets build-ruby-app-server: Vineet tyagi
ThoughtWorks
 
PDF
TorqueBox for Rubyists
bobmcwhirter
 
KEY
Ruby on Rails survival guide of an aged Java developer
gicappa
 
KEY
Ruby Concurrency Realities
Mike Subelsky
 
PDF
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
PDF
Concurrency & Ruby
rockyjaiswal
 
KEY
Concurrency in ruby
Marco Borromeo
 
PDF
TorqueBox at DC:JBUG - November 2011
bobmcwhirter
 
PPTX
Day 1 - Intro to Ruby
Barry Jones
 
ODP
JRuby - Everything in a single process
ocher
 
PDF
Practical Intro Merb
Paul Pajo
 
PDF
Practical Intro Merb
Paul Pajo
 
PDF
Ruby's Concurrency Management: Now and Future
Koichi Sasada
 
PDF
Concurrency: Rubies, Plural
Eleanor McHugh
 
PDF
Concurrency: Rubies, plural
ehuard
 
PPT
Workin ontherailsroad
Jim Jones
 
PPT
WorkinOnTheRailsRoad
webuploader
 
PDF
An introduction to the ruby ecosystem
Geison Goes
 
PDF
High Concurrent Ruby Web Development Without Fear
Delton Ding
 
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
Lets build-ruby-app-server: Vineet tyagi
ThoughtWorks
 
TorqueBox for Rubyists
bobmcwhirter
 
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Ruby Concurrency Realities
Mike Subelsky
 
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
Concurrency & Ruby
rockyjaiswal
 
Concurrency in ruby
Marco Borromeo
 
TorqueBox at DC:JBUG - November 2011
bobmcwhirter
 
Day 1 - Intro to Ruby
Barry Jones
 
JRuby - Everything in a single process
ocher
 
Practical Intro Merb
Paul Pajo
 
Practical Intro Merb
Paul Pajo
 
Ruby's Concurrency Management: Now and Future
Koichi Sasada
 
Concurrency: Rubies, Plural
Eleanor McHugh
 
Concurrency: Rubies, plural
ehuard
 
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
webuploader
 
An introduction to the ruby ecosystem
Geison Goes
 
High Concurrent Ruby Web Development Without Fear
Delton Ding
 
Ad

More from Engine Yard (19)

POTX
Engine Yard Partner Program 2014
Engine Yard
 
PDF
Getting Started with PHP on Engine Yard Cloud
Engine Yard
 
PDF
Engine Yard Cloud Architecture Enhancements
Engine Yard
 
PDF
6 tips for improving ruby performance
Engine Yard
 
PDF
Simplifying PCI on a PaaS Environment
Engine Yard
 
PDF
The Tao of Documentation
Engine Yard
 
PDF
Innovate Faster in the Cloud with a Platform as a Service
Engine Yard
 
PDF
Introduction to Ruby
Engine Yard
 
PDF
JRuby: Enhancing Java Developers Lives
Engine Yard
 
PDF
Release Early & Release Often: Reducing Deployment Friction
Engine Yard
 
PDF
JRuby Jam Session
Engine Yard
 
PDF
Rubinius and Ruby | A Love Story
Engine Yard
 
KEY
Rails Antipatterns | Open Session with Chad Pytel
Engine Yard
 
PDF
JRuby: Apples and Oranges
Engine Yard
 
PDF
Developing a Language
Engine Yard
 
PDF
Debugging Ruby Systems
Engine Yard
 
KEY
Geemus
Engine Yard
 
PDF
Everything Rubinius
Engine Yard
 
PDF
Rails Hosting and the Woes
Engine Yard
 
Engine Yard Partner Program 2014
Engine Yard
 
Getting Started with PHP on Engine Yard Cloud
Engine Yard
 
Engine Yard Cloud Architecture Enhancements
Engine Yard
 
6 tips for improving ruby performance
Engine Yard
 
Simplifying PCI on a PaaS Environment
Engine Yard
 
The Tao of Documentation
Engine Yard
 
Innovate Faster in the Cloud with a Platform as a Service
Engine Yard
 
Introduction to Ruby
Engine Yard
 
JRuby: Enhancing Java Developers Lives
Engine Yard
 
Release Early & Release Often: Reducing Deployment Friction
Engine Yard
 
JRuby Jam Session
Engine Yard
 
Rubinius and Ruby | A Love Story
Engine Yard
 
Rails Antipatterns | Open Session with Chad Pytel
Engine Yard
 
JRuby: Apples and Oranges
Engine Yard
 
Developing a Language
Engine Yard
 
Debugging Ruby Systems
Engine Yard
 
Geemus
Engine Yard
 
Everything Rubinius
Engine Yard
 
Rails Hosting and the Woes
Engine Yard
 
Ad

Recently uploaded (20)

PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
July Patch Tuesday
Ivanti
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
July Patch Tuesday
Ivanti
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 

High Performance Ruby: Evented vs. Threaded