SlideShare una empresa de Scribd logo
1 de 32
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

Más contenido relacionado

Similar a 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 SafelyAcquia
 
[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.
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Web Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity ConferenceWeb Performance - Learnings from Velocity Conference
Web Performance - Learnings from Velocity ConferenceHardik Shah
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlMydbops
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAEWinston Chen
 
Mojo+presentation+1
Mojo+presentation+1Mojo+presentation+1
Mojo+presentation+1Craig Condon
 
Strategic Autovacuum
Strategic AutovacuumStrategic Autovacuum
Strategic AutovacuumScott Mead
 
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 CDNsGurpreet 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 ArchitecturesDerrick Isaacson
 
High performance website
High performance websiteHigh performance website
High performance websiteChamnap Chhorn
 

Similar a 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
 

Último

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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