SlideShare a Scribd company logo
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 wikia
Thursday, 30 May 13
SPEEDING UP RESPONSES
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
Thursday, 30 May 13
CACHING PARTIALS
• Self Expiring Cache Keys
• Nesting cached partials
• Touch Chains
Thursday, 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 children
Thursday, 30 May 13
TOUCH CHAINS
LessonView LessonView LessonView
Enrollment Enrollment
User
Thursday, 30 May 13
NESTED CACHED PARTIALS
• Update enrollment = n-1 partials still cached.
• Parent cache expired, but uses many nested caches = quick to
rebuild
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
Thursday, 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 content
Thursday, 30 May 13
ACTION CACHING
• Same as page caching but allows before filters
• Caches to the cache_store, not public folder
Thursday, 30 May 13
EXPIRING PAGE / ACTION
CACHES
• Manual cache clearing != fun
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
Thursday, 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 content
Thursday, 30 May 13
CONDITIONAL GETS
• 560ms
• 149ms
Thursday, 30 May 13
A BETTERTOUCH CHAIN
• updated_at on User? CHANGES ALLTHETIME
• belongs_to :user,
touch: :enrollments_updated_at
• updated_at columns for various children
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
Thursday, 30 May 13
CDN’S EVERYWHERE
• Speed of light is a limiting factor
• AU <-> US 110ms
• AU <-> AU 40ms
Thursday, 30 May 13
CDN’S AREN’T JUST FOR
STATIC CONTENT
SYN
SYNACK
RESPONSE
REQUEST
NO CDN
110ms
110ms
110ms
110ms
= 440ms
Thursday, 30 May 13
CDN’S AREN’T JUST FOR
STATIC CONTENT
SYN
SYNACK
RESPONSE
REQUEST
CDN
40ms
40ms
110ms
110ms
= 300ms (31% less)
CDN uses Keep Alive to
connect to origin (us)
Thursday, 30 May 13
SPEEDING UP RESPONSES
• Template Caching
• Partials
• Actions
• Browser Caching
• CDN’s Everywhere
• Bonus
Thursday, 30 May 13
ACTIVERECORD QUERY
CACHING
• Course Load (129.4ms) SELECT `courses`.* FROM `courses`
• CACHE (0.0ms) SELECT `courses`.* FROM `courses`
• Doesn’t work across requests
Thursday, 30 May 13
ACTIVERECORD QUERY
CACHING
• Caches AR query across requests in Redis
• Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100
Processing 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[0m
Completed 200 OK in 13ms (ActiveRecord: 1.8ms)
• Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100
Processing byVisitTagController#create as */*
Completed 200 OK in 13ms (ActiveRecord: 0ms)
Thursday, 30 May 13

More Related Content

Similar to Speed up Rails Responses

Views Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views SafelyViews Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views Safely
Acquia
 
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
Insight Technology, Inc.
 
Js memory
Js memoryJs memory
Js memory
Ynon Perek
 
Strategic autovacuum
Strategic autovacuumStrategic autovacuum
Strategic autovacuum
Jim Mlodgenski
 
Perf tuning2
Perf tuning2Perf tuning2
Perf tuning2
Anis Berejeb
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
Barry Jones
 
Jbpm Console NG - JudCon Brazil 2013
Jbpm Console NG - JudCon Brazil 2013Jbpm Console NG - JudCon Brazil 2013
Jbpm Console NG - JudCon Brazil 2013
Mauricio (Salaboy) Salatino
 
Web Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity ConferenceWeb Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity Conference
Hardik Shah
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in Postgresql
Mydbops
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAE
Winston Chen
 
Mojo+presentation+1
Mojo+presentation+1Mojo+presentation+1
Mojo+presentation+1
Craig Condon
 
Strategic Autovacuum
Strategic AutovacuumStrategic Autovacuum
Strategic Autovacuum
Scott Mead
 
Performance
PerformancePerformance
Performance
Ynon Perek
 
UberFire (JudCon 2013)
UberFire (JudCon 2013)UberFire (JudCon 2013)
UberFire (JudCon 2013)
Mark Proctor
 
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
DevOpsDays Tel Aviv
 
Harnessing The Power of CDNs
Harnessing The Power of CDNsHarnessing The Power of CDNs
Harnessing The Power of CDNs
Gurpreet Luthra
 
Prisoner's Dilemma and Service-oriented Architectures
Prisoner's Dilemma and Service-oriented ArchitecturesPrisoner's Dilemma and Service-oriented Architectures
Prisoner's Dilemma and Service-oriented Architectures
Derrick Isaacson
 
Deep Dive on Amazon S3
Deep Dive on Amazon S3Deep Dive on Amazon S3
Deep Dive on Amazon S3
Amazon Web Services
 
Salesforce Performance hacks - Client Side
Salesforce Performance hacks - Client SideSalesforce Performance hacks - Client Side
Salesforce Performance hacks - Client Side
Paris Salesforce Developer Group
 
High performance website
High performance websiteHigh performance website
High performance website
Chamnap Chhorn
 

Similar to Speed up Rails Responses (20)

Views Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views SafelyViews Mini-Course, Part III: How to Back Up Your Views Safely
Views Mini-Course, Part III: How to Back Up Your Views Safely
 
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
[db tech showcase Tokyo 2017] C32: Patterns for building hybrid scenarios wit...
 
Js memory
Js memoryJs memory
Js memory
 
Strategic autovacuum
Strategic autovacuumStrategic autovacuum
Strategic autovacuum
 
Perf tuning2
Perf tuning2Perf tuning2
Perf tuning2
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Jbpm Console NG - JudCon Brazil 2013
Jbpm Console NG - JudCon Brazil 2013Jbpm Console NG - JudCon Brazil 2013
Jbpm Console NG - JudCon Brazil 2013
 
Web Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity ConferenceWeb Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity Conference
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in Postgresql
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAE
 
Mojo+presentation+1
Mojo+presentation+1Mojo+presentation+1
Mojo+presentation+1
 
Strategic Autovacuum
Strategic AutovacuumStrategic Autovacuum
Strategic Autovacuum
 
Performance
PerformancePerformance
Performance
 
UberFire (JudCon 2013)
UberFire (JudCon 2013)UberFire (JudCon 2013)
UberFire (JudCon 2013)
 
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
Debugging Skynet: A Machine Learning Approach to Log Analysis - Ianir Ideses,...
 
Harnessing The Power of CDNs
Harnessing The Power of CDNsHarnessing The Power of CDNs
Harnessing The Power of CDNs
 
Prisoner's Dilemma and Service-oriented Architectures
Prisoner's Dilemma and Service-oriented ArchitecturesPrisoner's Dilemma and Service-oriented Architectures
Prisoner's Dilemma and Service-oriented Architectures
 
Deep Dive on Amazon S3
Deep Dive on Amazon S3Deep Dive on Amazon S3
Deep Dive on Amazon S3
 
Salesforce Performance hacks - Client Side
Salesforce Performance hacks - Client SideSalesforce Performance hacks - Client Side
Salesforce Performance hacks - Client Side
 
High performance website
High performance websiteHigh performance website
High performance website
 

Recently uploaded

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

Speed up Rails Responses

  • 1. SPEEDING UP OUR APPS (not start up time) Thursday, 30 May 13
  • 4. Based on several billion requests to wikia Thursday, 30 May 13
  • 6. SPEEDING UP RESPONSES • Template Caching Thursday, 30 May 13
  • 7. SPEEDING UP RESPONSES • Template Caching • Partials Thursday, 30 May 13
  • 8. SPEEDING UP RESPONSES • Template Caching • Partials • Actions Thursday, 30 May 13
  • 9. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching Thursday, 30 May 13
  • 10. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere Thursday, 30 May 13
  • 11. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere Thursday, 30 May 13
  • 12. CACHING PARTIALS • Self Expiring Cache Keys • Nesting cached partials • Touch Chains Thursday, 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 children Thursday, 30 May 13
  • 16. TOUCH CHAINS LessonView LessonView LessonView Enrollment Enrollment User Thursday, 30 May 13
  • 17. NESTED CACHED PARTIALS • Update enrollment = n-1 partials still cached. • Parent cache expired, but uses many nested caches = quick to rebuild Thursday, 30 May 13
  • 18. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere Thursday, 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 content Thursday, 30 May 13
  • 20. ACTION CACHING • Same as page caching but allows before filters • Caches to the cache_store, not public folder Thursday, 30 May 13
  • 21. EXPIRING PAGE / ACTION CACHES • Manual cache clearing != fun Thursday, 30 May 13
  • 22. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere Thursday, 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 content Thursday, 30 May 13
  • 24. CONDITIONAL GETS • 560ms • 149ms Thursday, 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 children Thursday, 30 May 13
  • 26. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere Thursday, 30 May 13
  • 27. CDN’S EVERYWHERE • Speed of light is a limiting factor • AU <-> US 110ms • AU <-> AU 40ms Thursday, 30 May 13
  • 28. CDN’S AREN’T JUST FOR STATIC CONTENT SYN SYNACK RESPONSE REQUEST NO CDN 110ms 110ms 110ms 110ms = 440ms Thursday, 30 May 13
  • 29. CDN’S AREN’T JUST FOR STATIC CONTENT SYN SYNACK RESPONSE REQUEST CDN 40ms 40ms 110ms 110ms = 300ms (31% less) CDN uses Keep Alive to connect to origin (us) Thursday, 30 May 13
  • 30. SPEEDING UP RESPONSES • Template Caching • Partials • Actions • Browser Caching • CDN’s Everywhere • Bonus Thursday, 30 May 13
  • 31. ACTIVERECORD QUERY CACHING • Course Load (129.4ms) SELECT `courses`.* FROM `courses` • CACHE (0.0ms) SELECT `courses`.* FROM `courses` • Doesn’t work across requests Thursday, 30 May 13
  • 32. ACTIVERECORD QUERY CACHING • Caches AR query across requests in Redis • Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100 Processing 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[0m Completed 200 OK in 13ms (ActiveRecord: 1.8ms) • Started GET "/visit/tag.gif" for 192.168.33.10 at 2013-02-20 11:28:28 +1100 Processing byVisitTagController#create as */* Completed 200 OK in 13ms (ActiveRecord: 0ms) Thursday, 30 May 13