Faster on Rails
-
Upload
david-paluy -
Category
Self Improvement
-
view
1.793 -
download
0
Transcript of Faster on Rails
Blue Border
Faster on Rails
David PaluyMay 28, 2012
Me
Co-Founder, Startup.
Previously, Co-Founder AlgoTrading Startup
Working with Ruby, since 2007
dpaluy
dpaluy
davidpaluy
IsraelRb @LinkedIn
Agenda
Usability
Web Servers
Rack Web Servers
Back-end
Front-end
Note: Links
CNN Example
Source
WebPage Test by Google
Usability
DelayUser Reaction
0-100 msInstant
0-300 msFeels sluggish
100-1000msMachine is working...
1s +Mental context switch
10s +I'll come back later...
Source
Usability
DelayUser Reaction
0-100 msInstant
0-300 msFeels sluggish
100-1000msMachine is working...
1s +Mental context switch
We're here!!! (on average...)
10s +I'll come back later...
Source
Navigation Timing (W3C)
Source
Measuring Site Speed with Navigation Timing Ilya Grigorik
WebPageTest
NY Times - test
Best Practice:
Measure
Analyze
Optimize
Scaling Rails
View 21 ScreenCasts by Gregg Pollack
Web Servers
Process-Based ServerEvent-Based Server- In a process-based server, each simultaneous connection requires a thread which incurs significant overhead.- An asynchronous server is event-driven and handles requests in a single (or at least, very few) threads.
Web Servers: Apache vs Nginx
Source
Web Servers: Apache vs Nginx
Source
The main advantage of the asynchronous approach is scalability!
Rack Web Server
Source
Rack Web Server by
Source
Rack Web Server by
Source
Rack Web Server
Don't use Unicorn without NGINX!VS
Read more about Unicorn here
Unicorn sucks at:
3rd-party APIs
OpenID consumers
Reverse proxy implementations with editing/censoring
HTTP server push
Long polling
Reverse AJAX
Real-time upload processing
Rainbows! - Unicorn for sleepy apps and slow clients
Rainbows ThreadPool Application
Read more about Rainbows here and Github
Source
Back-End
HTTP Pipelining Communication
SPDY by Google
Allows client and server to compress request and response headers
Allows multiple, simultaneously multiplexed requests over a single connection
Allows the server to actively push resources to the client that it knows the client will need (e.g. JavaScript and CSS files)
SPDY on Rails by Roman Shterenzon
Databases
N+1 redundancy
Hot Standby - A method of redundancy in which the primary and secondary (i.e., backup) systems run simultaneously. The data is mirrored to the secondary server in real time so that both systems contain identical information.
Warm Standby - A method of redundancy in which the secondary (i.e., backup) system runs in the background of the primary system. Data is mirrored to the secondary server at regular intervals, which means that there are times when both servers do not contain the exact same data.
Cold Standby - A method of redundancy in which the secondary system is only called upon when the primary system fails. The system on cold standby receives scheduled data backups, but less frequently than a warm standby. Used for non-critical applications or in cases where data is changed infrequently.
Tidbits: Automatic Query Explains (Rails 3.2)
Log slow queries:
Console:
Source
Tidbits: Giant queries loading everything into memory
Source
Tidbits: Kill Long Running Requests
Tidbits: Favicons and 404 Errors
Avoid
Tidbits: Linux Server
ulimit -n
memcached -t x // x CPU cores
Monitor everything
(StatsD with Graphite, Munin, NewRelic, UnionStation)
Client Side
YSlow
PageSpeed by Google
HAML vs ERB (Source)
How to make your JavaScript Fast
Wish you Faster Browsing!
Scaling = replacing all components of a car while driving it at 100 mph (Mike Krieger, Instagram)
References
WebPage Test by Google
PageSpeed by Google
SPDY by Google
How to scale a Ruby Web Service
Scaling Instagram
Measuring Site Speed with Navigation Timing
Thank you!