Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
High-Performance Ruby: Evented vs readed @drnic | drnicwilliams.com | engineyard.com Dr Nic Williams
Slide 2
Slide 2 text
“ruby midwest”
Slide 3
Slide 3 text
“ruby midwest”
Slide 4
Slide 4 text
midwest
Slide 5
Slide 5 text
midwest
Slide 6
Slide 6 text
kansas
Slide 7
Slide 7 text
kansas city
Slide 8
Slide 8 text
in Missouri
Slide 9
Slide 9 text
midwest?!
Slide 10
Slide 10 text
an actual safari
Slide 11
Slide 11 text
________ < Safari > -‐-‐-‐-‐-‐-‐-‐-‐ \ ^__^ \ (xx)\_______ (__)\ )\/\ ^ ||-‐-‐-‐-‐w | || ||
Slide 12
Slide 12 text
drnic cowsay
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
You have $
Slide 15
Slide 15 text
New project/rapid dev Optimise (features/$) (req latency/$) (req thru-put/$) (bugs/$)
Slide 16
Slide 16 text
Add resources
Slide 17
Slide 17 text
Resources = $ $
Slide 18
Slide 18 text
or even $$$$$ $ $ $ $ $
Slide 19
Slide 19 text
Optimise New project/rapid dev (features/$) (performance/$0) how?
Slide 20
Slide 20 text
No content
Slide 21
Slide 21 text
•Add resources •Use resources better Options
Slide 22
Slide 22 text
you? just write code
Slide 23
Slide 23 text
evented -> threads -> your code
Slide 24
Slide 24 text
nginx -> trinidad -> web app
Slide 25
Slide 25 text
evented? arrange I/O
Slide 26
Slide 26 text
threads? actual work
Slide 27
Slide 27 text
you? just write code
Slide 28
Slide 28 text
evented -> threads -> your code
Slide 29
Slide 29 text
nginx -> trinidad -> web app
Slide 30
Slide 30 text
•Add resources •Use resources better Options
Slide 31
Slide 31 text
•process concurrency •threaded concurrency •evented concurrency Concurrency
Slide 32
Slide 32 text
Process vs readed
Slide 33
Slide 33 text
•1 req = 1 process = 150Mb •“100 reqs?” = 15Gb! •Orchestrated by? Kernel •Unicorn, Passenger Process Concurrency
Slide 34
Slide 34 text
•1 req = 1 thread = 2kb •“100 reqs?”=150Mb+200kb •Orchestrated by? Kernel •Mongrel* readed Concurrency
Slide 35
Slide 35 text
1 req = 1 thread = 2kb
Slide 36
Slide 36 text
Process vs readed
Slide 37
Slide 37 text
evented -> threads -> your code
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
•.... •.... •.... •Mongrel* readed Concurrency
Slide 40
Slide 40 text
•.... •.... •.... •Mongrel* readed Concurrency
Slide 41
Slide 41 text
“Mongrel is threaded?!”
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
Mongrel * Rails * Ruby1.8 --> process conc. 2006 reality:
Slide 44
Slide 44 text
20068 reality: “Rails 2.2... rst...thread safe Rails” --Pratik Naik
Slide 45
Slide 45 text
20068 reality: config.threadsafe! http://guides.rubyonrails.org/configuring.html
Slide 46
Slide 46 text
20068 reality: # do nothing http://www.sinatrarb.com/configuration.html
Slide 47
Slide 47 text
Mongrel * Rails * Ruby1.8 --> process conc. 20068 reality:
Slide 48
Slide 48 text
200810 reality: “Ruby 1.9.2 is released”
Slide 49
Slide 49 text
200810 reality: 1.9 has native threads!
Slide 50
Slide 50 text
200810 reality: 1 thread of Ruby at a time :(
Slide 51
Slide 51 text
200810 reality: GIL = Global Interpreter Lock :(
Slide 52
Slide 52 text
200810 reality: GIL:( “Grumpy Gil”
Slide 53
Slide 53 text
Mongrel * Rails * Ruby1.9 --> process conc. 200810 reality:
Slide 54
Slide 54 text
“Mongrel is threaded?!” “Rails is threadsafe” but no threads...
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
“reads please!”
Slide 57
Slide 57 text
rvm install jruby rvm use jruby gem install rails rails new myapp
Slide 58
Slide 58 text
gem 'activerecord- jdbcsqlite3- adapter' gem 'jruby-openssl'
Slide 59
Slide 59 text
Mongrel * Rails * JRuby --> thread concurrency!
Slide 60
Slide 60 text
1 req = 1 thread = 2kb
Slide 61
Slide 61 text
“How do I run JRuby/ Rails?”
Slide 62
Slide 62 text
How? -> trinidad -> web app
Slide 63
Slide 63 text
$ gem install trinidad $ trinidad --> localhost:3000
Slide 64
Slide 64 text
$ git clone git:// github.com/ engineyard/todo.git $ cd todo $ bundle $ rake db:migrate $ trinidad
Slide 65
Slide 65 text
# config.threadsafe! $ trinidad Info: max runtimes = 5
Slide 66
Slide 66 text
config.threadsafe! # yes! $ trinidad -e production Info: max runtimes = 1 (Thread limit 200)
Slide 67
Slide 67 text
1 req = 1 thread = 2kb
Slide 68
Slide 68 text
And its just normal web app code!
Slide 69
Slide 69 text
evented -> threads -> your code
Slide 70
Slide 70 text
nginx -> trinidad -> web app
Slide 71
Slide 71 text
“I’m scared of threads”
Slide 72
Slide 72 text
Web apps are* thread safe
Slide 73
Slide 73 text
“Store state elsewhere; Unless its safe” Dr Nic’s Joy of Concurrency
Slide 74
Slide 74 text
No content
Slide 75
Slide 75 text
evented -> threads -> your code
Slide 76
Slide 76 text
nginx -> trinidad -> web app
Slide 77
Slide 77 text
“I came to hear good things about EventMachine”
Slide 78
Slide 78 text
“Evented is cool, threads are not”
Slide 79
Slide 79 text
“You haven’t said ‘nodejs’ once!?”
Slide 80
Slide 80 text
What is evented? any I/O? do something with it
Slide 81
Slide 81 text
cache hits req ? web app cache miss
Slide 82
Slide 82 text
cache hits req ? web app cache miss
Slide 83
Slide 83 text
req I/O work
Slide 84
Slide 84 text
req I/O work evented threads
Slide 85
Slide 85 text
req I/O work evented threads trinidad nginx
Slide 86
Slide 86 text
nginx vs apache
Slide 87
Slide 87 text
“Hosted?” 500 hrs free!
Slide 88
Slide 88 text
jruby core trinidad core rubinius core Come work with us!
Slide 89
Slide 89 text
-> your code “Be a happy developer”
Slide 90
Slide 90 text
-> threads -> your code
Slide 91
Slide 91 text
evented -> threads -> your code
Slide 92
Slide 92 text
nginx -> trinidad -> web app @drnic | drnicwilliams.com | engineyard.com
Slide 93
Slide 93 text
_____________ < Power Ruby! > -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐ \ ^__^ \ (Oo)\_______ (__)\ )\/\ <> ||-‐-‐-‐-‐w | || || @drnic | drnicwilliams.com | engineyard.com