High Concurrent Ruby Web
Development Without Fear
Delton Ding
GitHub: @dsh0416
Twitter: @DeltonDing
High Concurrent Ruby Web
Development Without Fear
Delton Ding
GitHub: @dsh0416
Twitter: @DeltonDing
Yet Another Trip To Japan
Yet Another Trip To Japan
Yet Another Trip To Japan
A Fresh New Japan Adventure
Check-in 16:00
Check-in 16:00
Check-in 27:00
Concurrency Goals
•Defeat Erlang/Go/Crystal/…
•Defeat Erlang/Go/Crystal/…
•Sweet Spot
•Easy to use just like your previous Ruby projects
•Easy to use just like your previous Ruby projects
•Giving enough time to migrate to other language
There’re only ten minutes before my flight…
•Easy to use just like your previous Ruby projects
•Giving enough time to migrate to other language
Is Ruby Slow?
Is Ruby Slow?
Yes, it is.
H E A P S O RT ( 1 0 ^ 7 E L E M E N T S )
C++ (clang-800)
Go 1.7.4
Swift 3.0.1
Rust 1.13
Java 8
Crystal
Node 7.2.1
Pypy3 5.5.0
LuaJIT 2.0.4
Elixir 1.4.0
Truffle Ruby
JRuby 9.1.6.0
PHP 7.0
Ruby 2.4.0
PHP 5.6
Lua 5.2.4
Python 3.6.0
Perl 5.18.2
mruby 1.3.0
Perl 6 (2017-7)
1
10
100
1,000
10,000
100,000
1,000,000
1,208,725
405,465
172,625
140,208
90,171
84,900
47,290
41,404
32,272
7,574
4,075
2,822
2,182
2,052
1,669
1,373
1,156
1,085
817
759
Running Time (ms)
Benchmark
My name is Link.
Stop calling me Zelda.
Web Server Basic
Views + DB
(Sequel)
WEBrick 273 req/s 111 req/s
Thin 1597 req/s 139 req/s
Unicorn 605 req/s 121 req/s
Asynchronous
•Why Ruby Needs Asynchronous Web Server Eagerly?
•Why Asynchronous Development So Hard?
–Yukihiro Matsumoto, a.k.a. Matz
“Ruby is designed to make programmers happy.”
EM.run do
http = EM HttpRequest.new(‘https://www.google.co.jp/').get
http.callback do

puts result

EM.stop

end

puts 'Requesting...'

end
Attempt
API call Database I/O
Call
Callback
Call
API call Database I/O
Yield
Resume
Fiber
I/O Pool
With nio4r
Fiber Pool
With Fiber
Resume
Yield
New
What if
midori
github.com/heckpsi-lab/em-midori
Goals
• No I/O Blocking
• Lightweight Stack Design
•Meta-programming Database/ORM/Redis/Redis ORM/…
•Engineering Capability
Demo
Performance
Web Server Basic DB (Sequel)
Sinatra (Thin) 1597 req/s 111 req/s
Midori 3937 req/s 1726 req/s
Express.js (Node) 4944 req/s 2151 req/s
Middleware
Middleware
Middleware
Middleware
Middleware
Request Response
API
Middleware
Middleware
Middleware
Middleware
Middleware
Request
API
Other Tricks
Realtime Communication
Next Steps
Next Steps
•Website/Tutorial
•API Stable
•I/O Improvement
•Clusters
•Scaffold
Thanks
Delton Ding
GitHub: @dsh0416
Twitter: @DeltonDing

High Concurrent Ruby Web Development Without Fear