• Save
Speed up Rails Responses
Upcoming SlideShare
Loading in...5
×
 

Speed up Rails Responses

on

  • 1,011 views

My slides from a lightning talk I gave to SitePoint / Learnable devs earlier this year.

My slides from a lightning talk I gave to SitePoint / Learnable devs earlier this year.

Statistics

Views

Total Views
1,011
Views on SlideShare
1,008
Embed Views
3

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 3

https://twitter.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Speed up Rails Responses Speed up Rails Responses Presentation Transcript

    • SPEEDING UP OUR APPS(not start up time)Thursday, 30 May 13
    • Thursday, 30 May 13
    • ?Thursday, 30 May 13
    • Based on several billion requests to wikiaThursday, 30 May 13
    • SPEEDING UP RESPONSESThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template CachingThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• PartialsThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• ActionsThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser CachingThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
    • CACHING PARTIALS• Self Expiring Cache Keys• Nesting cached partials• Touch ChainsThursday, 30 May 13
    • SELF EXPIRING CACHE KEYS• Calls #cache_key on @user• [class]/[id]-[updated_at]• ‘users/2-20130220103049’Thursday, 30 May 13
    • CONTEXT IS KING• Provide a unique key for each context• Increment version when you change the html.Thursday, 30 May 13
    • TOUCH CHAINS• Sets the parent model’s #updated_at toTime.now• Touch parents, not childrenThursday, 30 May 13
    • TOUCH CHAINSLessonView LessonView LessonViewEnrollment EnrollmentUserThursday, 30 May 13
    • NESTED CACHED PARTIALS• Update enrollment = n-1 partials still cached.• Parent cache expired, but uses many nested caches = quick torebuildThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
    • PAGE CACHING• Saves entire page to xyz.html in public• Can serve up as gzipped• Fast!• Generally useless for anything but public static contentThursday, 30 May 13
    • ACTION CACHING• Same as page caching but allows before filters• Caches to the cache_store, not public folderThursday, 30 May 13
    • EXPIRING PAGE / ACTIONCACHES• Manual cache clearing != funThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
    • CONDITIONAL GETS• Utilizes HTTP_IF_NONE_MATCH and IF_MODIFIED_SINCE• Returns a HEAD 304 (not modified) response• Does not render any contentThursday, 30 May 13
    • CONDITIONAL GETS• 560ms• 149msThursday, 30 May 13
    • A BETTERTOUCH CHAIN• updated_at on User? CHANGES ALLTHETIME• belongs_to :user,touch: :enrollments_updated_at• updated_at columns for various childrenThursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
    • CDN’S EVERYWHERE• Speed of light is a limiting factor• AU <-> US 110ms• AU <-> AU 40msThursday, 30 May 13
    • CDN’S AREN’T JUST FORSTATIC CONTENTSYNSYNACKRESPONSEREQUESTNO CDN110ms110ms110ms110ms= 440msThursday, 30 May 13
    • CDN’S AREN’T JUST FORSTATIC CONTENTSYNSYNACKRESPONSEREQUESTCDN40ms40ms110ms110ms= 300ms (31% less)CDN uses Keep Alive toconnect to origin (us)Thursday, 30 May 13
    • SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s Everywhere• BonusThursday, 30 May 13
    • ACTIVERECORD QUERYCACHING• Course Load (129.4ms) SELECT `courses`.* FROM `courses`• CACHE (0.0ms) SELECT `courses`.* FROM `courses`• Doesn’t work across requestsThursday, 30 May 13
    • ACTIVERECORD QUERYCACHING• Caches AR query across requests in Redis• Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100Processing byVisitTagController#create as */*[1m[36mUser Load (0.7ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1[0m[1m[35mFeature Load (0.4ms)[0m SELECT `features`.* FROM `features` WHERE `features`.`key` = intercept_renewal_failed_members LIMIT 1[1m[36mCACHE (0.0ms)[0m [1mSELECT `features`.* FROM `features` WHERE `features`.`key` = intercept_renewal_failed_members LIMIT 1[0m[1m[35mFeature Load (0.3ms)[0m SELECT `features`.* FROM `features` WHERE `features`.`key` = redirect_agreement_update LIMIT 1[1m[36mCACHE (0.0ms)[0m [1mSELECT `features`.* FROM `features` WHERE `features`.`key` = redirect_agreement_update LIMIT 1[0m[1m[35mFeature Load (0.4ms)[0m SELECT `features`.* FROM `features` WHERE `features`.`key` = testmode LIMIT 1[1m[36mCACHE (0.0ms)[0m [1mSELECT `features`.* FROM `features` WHERE `features`.`key` = testmode LIMIT 1[0mCompleted 200 OK in 13ms (ActiveRecord: 1.8ms)• Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100Processing byVisitTagController#create as */*Completed 200 OK in 13ms (ActiveRecord: 0ms)Thursday, 30 May 13