Your SlideShare is downloading. ×
Speed up Rails Responses
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Speed up Rails Responses

839
views

Published on

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.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
839
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SPEEDING UP OUR APPS(not start up time)Thursday, 30 May 13
  • 2. Thursday, 30 May 13
  • 3. ?Thursday, 30 May 13
  • 4. Based on several billion requests to wikiaThursday, 30 May 13
  • 5. SPEEDING UP RESPONSESThursday, 30 May 13
  • 6. SPEEDING UP RESPONSES• Template CachingThursday, 30 May 13
  • 7. SPEEDING UP RESPONSES• Template Caching• PartialsThursday, 30 May 13
  • 8. SPEEDING UP RESPONSES• Template Caching• Partials• ActionsThursday, 30 May 13
  • 9. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser CachingThursday, 30 May 13
  • 10. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
  • 11. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
  • 12. CACHING PARTIALS• Self Expiring Cache Keys• Nesting cached partials• Touch ChainsThursday, 30 May 13
  • 13. SELF EXPIRING CACHE KEYS• Calls #cache_key on @user• [class]/[id]-[updated_at]• ‘users/2-20130220103049’Thursday, 30 May 13
  • 14. CONTEXT IS KING• Provide a unique key for each context• Increment version when you change the html.Thursday, 30 May 13
  • 15. TOUCH CHAINS• Sets the parent model’s #updated_at toTime.now• Touch parents, not childrenThursday, 30 May 13
  • 16. TOUCH CHAINSLessonView LessonView LessonViewEnrollment EnrollmentUserThursday, 30 May 13
  • 17. NESTED CACHED PARTIALS• Update enrollment = n-1 partials still cached.• Parent cache expired, but uses many nested caches = quick torebuildThursday, 30 May 13
  • 18. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
  • 19. 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
  • 20. ACTION CACHING• Same as page caching but allows before filters• Caches to the cache_store, not public folderThursday, 30 May 13
  • 21. EXPIRING PAGE / ACTIONCACHES• Manual cache clearing != funThursday, 30 May 13
  • 22. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
  • 23. 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
  • 24. CONDITIONAL GETS• 560ms• 149msThursday, 30 May 13
  • 25. 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
  • 26. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s EverywhereThursday, 30 May 13
  • 27. CDN’S EVERYWHERE• Speed of light is a limiting factor• AU <-> US 110ms• AU <-> AU 40msThursday, 30 May 13
  • 28. CDN’S AREN’T JUST FORSTATIC CONTENTSYNSYNACKRESPONSEREQUESTNO CDN110ms110ms110ms110ms= 440msThursday, 30 May 13
  • 29. CDN’S AREN’T JUST FORSTATIC CONTENTSYNSYNACKRESPONSEREQUESTCDN40ms40ms110ms110ms= 300ms (31% less)CDN uses Keep Alive toconnect to origin (us)Thursday, 30 May 13
  • 30. SPEEDING UP RESPONSES• Template Caching• Partials• Actions• Browser Caching• CDN’s Everywhere• BonusThursday, 30 May 13
  • 31. 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
  • 32. 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