Faster on Rails


David Paluy
May 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
Delay              User Reaction

0-100 ms           Instant

0-300 ms           Feels sluggish

100-1000ms         Machine is working...

1s +               Mental context switch

10s +              I'll come back later...


Source
Usability
Delay                       User Reaction

0-100 ms                    Instant

0-300 ms                    Feels sluggish

100-1000ms                  Machine 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 Server   Event-Based Server
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



                VS

                      Read more about Unicorn here




 Don't use Unicorn without NGINX!
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




 Source


          Read more about Rainbows here and Github
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
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!

Faster on Rails

Editor's Notes

  • #12 - 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.
  • #25 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.