SlideShare a Scribd company logo
1 of 55
Download to read offline
Rails
Need short bursts of speed?
I’m a thief



•   http://railslab.newrelic.com/
Perception
Communication:
          Two parts


•   Server speed
•   Browser speed
Browser speed


•   Firebug / Safari developer
•   YSlow
•   Different parts of a site
Webpage parts

•   Page itself (<html> ... )
•   Additional files (CSS, JavaScript)
•   Images
•   ... generating dynamic content
Siteparts


•   10 requests:10 times slower as one request
•   stylesheet_tag :defaults, ‘screen’, :cache => ‘all’
images


•   asset hosts
•   Content Delivery Network
Page Caching
Why?

•   Code parsing: 20 to 50 req/second
•   Webserver: easily > 100 req/sec
•   Webserver stresses less, less database queries
•   Why not, it is easy (with rails)...
implementation
result
expire_page
expires-result
conclusion: page cache


•   very simple
•   limited scope to apply
•   cache invalidation! Important!
Cache Expiry
Why not expire_page in
     the action?

•   Not DRY (update, create, destroy,...)
•   after_filter possible, but other controllers
    might need to expire the cache
after_filter
•   PostsController (clear_posts_cache)
•   CommentsController (clear_posts_cache)
sweeper


•   observer on controller and model
    •   if saved, call clear_posts_cache
    •   if deleted, call clear_posts_cache
how
Page caching - part 2



•   Ajax Callbacks for dynamic data
login/logout



•   pain!
Action Caching
Action cache

•   Cached output stored
•   Filters are processed before the cached
    version is returned to the browser
•   Example: authenticatie
caches_action
action cache


•   Filter is executed before sending the reply
•   Output is the same for everyone!
Welcome <username>

•   content is cached
•   layout is rendered
Warning! Attention!
•   fetch needed data with a before_filter
•   action is not executed!
Conditional AC

•   caching only on certain conditions
Action Caching

•   when?
    •   execute code on each hit (authentication)
    •   result remains the same
•   very easy to implement
Fragment Caching
Fragment caching


•   Cache part of a page
•   Logical blocks are candidates
Example
Fragment Caching
No useless actions
Fragment Cache expiry



•   expire_fragment
PC/AC Storage
Page cache storage
•   on disk
Storage: action /
          fragment cache
•   memory (default) or syncronised memory
•   file on disk
•   drb
•   memcache (normal or compressed)
•   custom_store (not hard to impelement!)
DYI
DYI caching


•   Caching hard parts in the code
•   Only spend cycles when really needed
Client-side caching



•   The cloud is there, use it
Three tags


•   max-age
•   etag
•   last_modified
max-age
etag


•   rails has this embedded
•   MD5(body) => etag
•   304 Not Modified
etag


•   Beware, the complete parsing is done!
•   Less bandwidth / traffic
•   Client load time faster
etag
last_modified
Scary technology?


•   memcached
•   reverse proxy’s
Memcached

•   Daemon
•   Is a big hash in memory
•   Rails has default routines for this
•   Hoster / setup should support this
Reverse Proxy’s


•   a proxy, but on the server side
•   controle over expiry: max_age + etag
•   expiry remains a pain
Rack::Cache

•   gem install rack-cache
•   rails 2.3 needed!
Need for speed?

•   Database (n+1, joins / includes)
•   Disk IO
•   Implementing caching
•   Browser caching
•   External components (CDN, memcached, ...)

More Related Content

What's hot

WebsitePerformance
WebsitePerformanceWebsitePerformance
WebsitePerformance
Vivek Jain
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
Gerald Villorente
 

What's hot (20)

Http caching 101 and a bit of CacheCow
Http caching 101 and a bit of CacheCowHttp caching 101 and a bit of CacheCow
Http caching 101 and a bit of CacheCow
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal Sites
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on NginxEasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
 
WebsitePerformance
WebsitePerformanceWebsitePerformance
WebsitePerformance
 
Ch. x web performance
Ch. x web performanceCh. x web performance
Ch. x web performance
 
SSDs are Awesome
SSDs are AwesomeSSDs are Awesome
SSDs are Awesome
 
JCache Using JCache
JCache Using JCacheJCache Using JCache
JCache Using JCache
 
Node.js
Node.jsNode.js
Node.js
 
Store
StoreStore
Store
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
 
Building WebLogic Domains With WLST
Building WebLogic Domains With WLSTBuilding WebLogic Domains With WLST
Building WebLogic Domains With WLST
 
Caching technology comparison
Caching technology comparisonCaching technology comparison
Caching technology comparison
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
 
Javascript & Jquery
Javascript & JqueryJavascript & Jquery
Javascript & Jquery
 
How to choose the right web hosting for your business
How to choose the right web hosting for your business How to choose the right web hosting for your business
How to choose the right web hosting for your business
 
Debugging WordPress Performance using EasyEngine
Debugging WordPress Performance using EasyEngineDebugging WordPress Performance using EasyEngine
Debugging WordPress Performance using EasyEngine
 
Memcached: What is it and what does it do?
Memcached: What is it and what does it do?Memcached: What is it and what does it do?
Memcached: What is it and what does it do?
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
In Memory Cahce Structure
In Memory Cahce StructureIn Memory Cahce Structure
In Memory Cahce Structure
 

Viewers also liked

Reinforcement unit 8
Reinforcement unit 8Reinforcement unit 8
Reinforcement unit 8
Sonia
 
campaña recogida de alimentos
campaña recogida de alimentoscampaña recogida de alimentos
campaña recogida de alimentos
pive
 
Facebook Places Mindshare
Facebook Places MindshareFacebook Places Mindshare
Facebook Places Mindshare
Rubén López
 
Reinforcement. unit 6
Reinforcement. unit 6Reinforcement. unit 6
Reinforcement. unit 6
Sonia
 
Teresa nuevo
Teresa nuevoTeresa nuevo
Teresa nuevo
serveduc
 
Iii jal pres_avaluaciocompetencial
Iii jal pres_avaluaciocompetencialIii jal pres_avaluaciocompetencial
Iii jal pres_avaluaciocompetencial
Arnau Cerdà
 
Wallets Collection
Wallets CollectionWallets Collection
Wallets Collection
kausarh
 

Viewers also liked (20)

Reinforcement unit 8
Reinforcement unit 8Reinforcement unit 8
Reinforcement unit 8
 
Moon
MoonMoon
Moon
 
campaña recogida de alimentos
campaña recogida de alimentoscampaña recogida de alimentos
campaña recogida de alimentos
 
Week10
Week10Week10
Week10
 
China Online Agency Round Up
China Online Agency Round UpChina Online Agency Round Up
China Online Agency Round Up
 
Facebook Places Mindshare
Facebook Places MindshareFacebook Places Mindshare
Facebook Places Mindshare
 
Reinforcement. unit 6
Reinforcement. unit 6Reinforcement. unit 6
Reinforcement. unit 6
 
Corbans 2010
Corbans 2010Corbans 2010
Corbans 2010
 
Wordpress33 base
Wordpress33 base Wordpress33 base
Wordpress33 base
 
Page Rank
Page RankPage Rank
Page Rank
 
Teresa nuevo
Teresa nuevoTeresa nuevo
Teresa nuevo
 
The indo tibetan tradition and the dharma in the west
 The indo tibetan tradition and the dharma in the west The indo tibetan tradition and the dharma in the west
The indo tibetan tradition and the dharma in the west
 
Lauris
LaurisLauris
Lauris
 
新たな社会貢献のカタチ
新たな社会貢献のカタチ新たな社会貢献のカタチ
新たな社会貢献のカタチ
 
Mães na Internet e o Cenário em Cuiabá
Mães na Internet e o Cenário em CuiabáMães na Internet e o Cenário em Cuiabá
Mães na Internet e o Cenário em Cuiabá
 
Iii jal pres_avaluaciocompetencial
Iii jal pres_avaluaciocompetencialIii jal pres_avaluaciocompetencial
Iii jal pres_avaluaciocompetencial
 
SOFTORIX Project TitlesList
SOFTORIX Project TitlesListSOFTORIX Project TitlesList
SOFTORIX Project TitlesList
 
The Last Problem You Had
The Last Problem You HadThe Last Problem You Had
The Last Problem You Had
 
Wallets Collection
Wallets CollectionWallets Collection
Wallets Collection
 
King arthur presentation with listening
King arthur presentation with listeningKing arthur presentation with listening
King arthur presentation with listening
 

Similar to Caching your rails application

Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupal
Ronan Berder
 
Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
evilmike
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
Acquia
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 

Similar to Caching your rails application (20)

Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the Edge
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the Edge
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
DrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an AfterthoughtDrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an Afterthought
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
 
Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupal
 
Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
 
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and TroubleshootOracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
 
Speed Matters
Speed MattersSpeed Matters
Speed Matters
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
 
Building Lightning Fast Websites (for Twin Cities .NET User Group)
Building Lightning Fast Websites (for Twin Cities .NET User Group)Building Lightning Fast Websites (for Twin Cities .NET User Group)
Building Lightning Fast Websites (for Twin Cities .NET User Group)
 
Platform Cache
Platform CachePlatform Cache
Platform Cache
 

More from ArrrrCamp (15)

Arrrrcamp Radiant Intro
Arrrrcamp Radiant IntroArrrrcamp Radiant Intro
Arrrrcamp Radiant Intro
 
Ruby 1.9 And Rails 3.0
Ruby 1.9 And Rails 3.0Ruby 1.9 And Rails 3.0
Ruby 1.9 And Rails 3.0
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds Ls
 
Rubyandrails
RubyandrailsRubyandrails
Rubyandrails
 
Nanoc
NanocNanoc
Nanoc
 
Git
GitGit
Git
 
Radiant
RadiantRadiant
Radiant
 
Mistakes
MistakesMistakes
Mistakes
 
Railsservers
RailsserversRailsservers
Railsservers
 
Prawn
PrawnPrawn
Prawn
 
Testing
TestingTesting
Testing
 
Validation
ValidationValidation
Validation
 
Cucumber
CucumberCucumber
Cucumber
 
Ruby and Rails Basics
Ruby and Rails BasicsRuby and Rails Basics
Ruby and Rails Basics
 
Advanced Radiant
Advanced RadiantAdvanced Radiant
Advanced Radiant
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Caching your rails application