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 ...
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 ...
ACTION CACHING• Same as page caching but allows before filters• Caches to the cache_store, not public folderThursday, 30 Ma...
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 r...
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 c...
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 toco...
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 ...
ACTIVERECORD QUERYCACHING• Caches AR query across requests in Redis• Started GET "/visit/tag.gif" for 192.168.33.10 at 201...
Upcoming SlideShare
Loading in …5
×

Speed up Rails Responses

1,261 views
1,056 views

Published on

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
1,261
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Speed up Rails Responses

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

×