SlideShare a Scribd company logo
The myth of unicorn
@isaiah_peng
What is a slow client
Request queue
• Put a nginx before your unicorn
• Profit!
Profit?
• unicorn is not suited for all applications. unicorn
is optimized for applications that are CPU/
memory/disk intensive and spend little time
waiting on external resources (e.g. a database
server or external API)
— The philosophy of unicorn
EventMachine / Thin
• Asynchronous IO, but
• Everything you do by default in Rails is blocking.
What’s the advantage
compared to unicorn?
* Non blocking (partly)
class Thin::Connection < EM::Connection
# When the request is received and parsed
def receive_data(data)
# anything happening here is blocking
resp = @app.call(Request.new.parse(data))
# handoff to EventMachine, non-blocking
send_data resp.body.join(“”)
end
end
* Persistent connection
CPU bounded
thin unicorn
IO bounded
thin unicorn
Potential problems
• Circular request
Asynchronous Rack?
require 'em-http-request'
app = -> env do
http = EM::HttpRequest.new("http://www.google.com").get
http.callback do
env['async.callback'].call([200, {}, http.response])
end
throw :async # read: yield
end
run app
(demo)
async_sinatra
• Demo (async_sinatra.ru)
• Good for normal usage
• Test `include Sinatra::Async::Test::Methods`
• Doesn’t work with Rack::URLMap, could be fixed
though
• The middleware has to be registered by the
‘async.callback’
Thread safety of MRI
• Native thread & GIL
• Demo (multi_thread.rb)
Puma
• Imagine a variation of unicorn that each worker has a
thread pool
• Designed for implementation with real thread
(Rubinius, JRuby)
• Puma still improves MRI's throughput by allowing
blocking IO to be run concurrently
• Cluster mode for MRI
• Thread-safety
Thread safety of Rails
• config.threadsafe! (Before Rails4)
• demo (rails.ru)
• Rack::Lock (puma cluster mode downgrade to
unicorn) Don’t gain much with JRuby / Rubinius
–Someone on the internet
“The speed of the web server doesn’t matter
that much, you request spends a very little
portion of time in the server.”
References
• http://www.rubydoc.info/github/rack/rack/file/SPEC
• http://unicorn.bogomips.org/PHILOSOPHY.html
• http://tenderlovemaking.com/2012/06/18/removing-
config-threadsafe.html
• http://www.rubyraptor.org/how-we-made-raptor-up-
to-4x-faster-than-unicorn-and-up-to-2x-faster-than-
puma-torquebox/
Thanks for your
attention!

More Related Content

PPTX
Alfresco Mvc - a seamless integration with Spring Mvc
PDF
Resilience testing with Wiremock and Spock
PDF
Prometheus Celery Exporter
PPTX
Mountebank and you
PDF
A Short Introduction to Servo (Web Engines Hackfest 2014)
PPTX
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
PDF
Top 5 Tools for Web Scraping
PPTX
Training on iOS app development - Samesh Swongamikha & Neetin Sharma
Alfresco Mvc - a seamless integration with Spring Mvc
Resilience testing with Wiremock and Spock
Prometheus Celery Exporter
Mountebank and you
A Short Introduction to Servo (Web Engines Hackfest 2014)
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Top 5 Tools for Web Scraping
Training on iOS app development - Samesh Swongamikha & Neetin Sharma

What's hot (14)

PPTX
Sql server update-lock
PPTX
Introducción a Wiremock
PDF
DevJam 2019 - Building an ALEC Time Engine
PPT
Intro to SPA using JavaScript & ASP.NET
PPTX
Spring Web flow. A little flow of happiness
PPTX
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
PPTX
Optimizing Access with SQL Server
PPTX
Owin & katana
PDF
How to Build Single Page HTML5 Apps that Scale
PDF
Laravel 4 presentation
PPTX
Selenium for Jobseekers
PDF
PWA to React Native migration
PPTX
Selenium Automation at Incapsula
PDF
Training Slides: 254 - Using the Tungsten Replicator AMI
Sql server update-lock
Introducción a Wiremock
DevJam 2019 - Building an ALEC Time Engine
Intro to SPA using JavaScript & ASP.NET
Spring Web flow. A little flow of happiness
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Optimizing Access with SQL Server
Owin & katana
How to Build Single Page HTML5 Apps that Scale
Laravel 4 presentation
Selenium for Jobseekers
PWA to React Native migration
Selenium Automation at Incapsula
Training Slides: 254 - Using the Tungsten Replicator AMI
Ad

Similar to The myth of unicorn (11)

KEY
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
ZIP
Message Queues in Ruby - An Overview
PPTX
HELM kubernetes package manager for beginner's
PDF
Asynchronous Ruby
KEY
TorqueBox - Ruby Hoedown 2011
PDF
Concurrency & Ruby
PDF
Ruby HTTP clients comparison
KEY
Concurrency in ruby
KEY
Ruby Concurrency Realities
PDF
Scaling Ruby with Evented I/O - Ruby underground
PPTX
Evented Ruby VS Node.js
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Message Queues in Ruby - An Overview
HELM kubernetes package manager for beginner's
Asynchronous Ruby
TorqueBox - Ruby Hoedown 2011
Concurrency & Ruby
Ruby HTTP clients comparison
Concurrency in ruby
Ruby Concurrency Realities
Scaling Ruby with Evented I/O - Ruby underground
Evented Ruby VS Node.js
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Modernizing your data center with Dell and AMD
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
Modernizing your data center with Dell and AMD
Unlocking AI with Model Context Protocol (MCP)
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

The myth of unicorn