SlideShare a Scribd company logo
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’
Caching your rails application
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
Caching your rails application
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 (20)

PDF
Http caching 101 and a bit of CacheCow
Ali Kheyrollahi
 
PDF
High Performance Drupal Sites
Abayomi Ayoola
 
PDF
Introduction to CQ5
Michele Mostarda
 
PDF
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
rtCamp
 
PDF
WebsitePerformance
Vivek Jain
 
PDF
Ch. x web performance
Manolis Vavalis
 
PDF
SSDs are Awesome
Barry Abrahamson
 
PDF
JCache Using JCache
日本Javaユーザーグループ
 
PPTX
Node.js
RTigger
 
PDF
Store
ESUG
 
PPTX
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
Nexcess.net LLC
 
PPTX
Building WebLogic Domains With WLST
C2B2 Consulting
 
PDF
Caching technology comparison
Rohit Kelapure
 
ODP
Drupal Performance and Scaling
Gerald Villorente
 
PPTX
Javascript & Jquery
Gurpreet singh
 
PPTX
How to choose the right web hosting for your business
Pickaweb
 
PDF
Debugging WordPress Performance using EasyEngine
rtCamp
 
KEY
Memcached: What is it and what does it do?
Brian Moon
 
PPTX
cache concepts and varnish-cache
Marc Cortinas Val
 
PPTX
In Memory Cahce Structure
Mehmet Ali Tastan
 
Http caching 101 and a bit of CacheCow
Ali Kheyrollahi
 
High Performance Drupal Sites
Abayomi Ayoola
 
Introduction to CQ5
Michele Mostarda
 
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
rtCamp
 
WebsitePerformance
Vivek Jain
 
Ch. x web performance
Manolis Vavalis
 
SSDs are Awesome
Barry Abrahamson
 
Node.js
RTigger
 
Store
ESUG
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
Nexcess.net LLC
 
Building WebLogic Domains With WLST
C2B2 Consulting
 
Caching technology comparison
Rohit Kelapure
 
Drupal Performance and Scaling
Gerald Villorente
 
Javascript & Jquery
Gurpreet singh
 
How to choose the right web hosting for your business
Pickaweb
 
Debugging WordPress Performance using EasyEngine
rtCamp
 
Memcached: What is it and what does it do?
Brian Moon
 
cache concepts and varnish-cache
Marc Cortinas Val
 
In Memory Cahce Structure
Mehmet Ali Tastan
 

Viewers also liked (20)

DOCX
Reinforcement unit 8
Sonia
 
PPT
campaña recogida de alimentos
pive
 
PDF
Week10
s1150188
 
PPT
China Online Agency Round Up
Abacus International
 
PPT
Facebook Places Mindshare
Rubén López
 
DOCX
Reinforcement. unit 6
Sonia
 
PPTX
Corbans 2010
uttamfloray
 
PDF
Wordpress33 base
Artlandis' Webinar & Workshop
 
PPT
Page Rank
Silvia Quimis
 
PPT
Teresa nuevo
serveduc
 
PDF
The indo tibetan tradition and the dharma in the west
Clear Vision Trust
 
PPT
Lauris
serveduc
 
PDF
新たな社会貢献のカタチ
ripper0217
 
PDF
Mães na Internet e o Cenário em Cuiabá
Matheus Moraes
 
PDF
Iii jal pres_avaluaciocompetencial
Arnau Cerdà
 
DOCX
SOFTORIX Project TitlesList
guest6071d14
 
KEY
The Last Problem You Had
Spoiled Milk
 
PDF
Wallets Collection
kausarh
 
PPT
King arthur presentation with listening
Mari Carmen Ocete, C.E.I.P. Francisco Giner de los Ríos
 
Reinforcement unit 8
Sonia
 
campaña recogida de alimentos
pive
 
Week10
s1150188
 
China Online Agency Round Up
Abacus International
 
Facebook Places Mindshare
Rubén López
 
Reinforcement. unit 6
Sonia
 
Corbans 2010
uttamfloray
 
Page Rank
Silvia Quimis
 
Teresa nuevo
serveduc
 
The indo tibetan tradition and the dharma in the west
Clear Vision Trust
 
Lauris
serveduc
 
新たな社会貢献のカタチ
ripper0217
 
Mães na Internet e o Cenário em Cuiabá
Matheus Moraes
 
Iii jal pres_avaluaciocompetencial
Arnau Cerdà
 
SOFTORIX Project TitlesList
guest6071d14
 
The Last Problem You Had
Spoiled Milk
 
Wallets Collection
kausarh
 
King arthur presentation with listening
Mari Carmen Ocete, C.E.I.P. Francisco Giner de los Ríos
 
Ad

Similar to Caching your rails application (20)

PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
Drupal performance
Piyuesh Kumar
 
KEY
Introduction to memcached
Jurriaan Persyn
 
PDF
Where Django Caching Bust at the Seams
Concentric Sky
 
PDF
Rails Caching: Secrets From the Edge
Fastly
 
PDF
Rails Caching Secrets from the Edge
Michael May
 
PPTX
Day 7 - Make it Fast
Barry Jones
 
PDF
DrupalSouth 2015 - Performance: Not an Afterthought
Nick Santamaria
 
PDF
Top ten-list
Brian DeShong
 
PDF
Ruby and Distributed Storage Systems
SATOSHI TAGOMORI
 
PDF
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
KEY
Performance and scalability with drupal
Ronan Berder
 
PDF
Building & Testing Scalable Rails Applications
evilmike
 
PDF
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Michel Schildmeijer
 
PDF
Speed Matters
Mark Stanton
 
PPT
5 Common Mistakes You are Making on your Website
Acquia
 
PDF
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Alluxio, Inc.
 
PDF
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
PPTX
Building Lightning Fast Websites (for Twin Cities .NET User Group)
strommen
 
PDF
Platform Cache
Salesforce Developers
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Drupal performance
Piyuesh Kumar
 
Introduction to memcached
Jurriaan Persyn
 
Where Django Caching Bust at the Seams
Concentric Sky
 
Rails Caching: Secrets From the Edge
Fastly
 
Rails Caching Secrets from the Edge
Michael May
 
Day 7 - Make it Fast
Barry Jones
 
DrupalSouth 2015 - Performance: Not an Afterthought
Nick Santamaria
 
Top ten-list
Brian DeShong
 
Ruby and Distributed Storage Systems
SATOSHI TAGOMORI
 
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
Performance and scalability with drupal
Ronan Berder
 
Building & Testing Scalable Rails Applications
evilmike
 
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Michel Schildmeijer
 
Speed Matters
Mark Stanton
 
5 Common Mistakes You are Making on your Website
Acquia
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Alluxio, Inc.
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ColdFusionConference
 
Building Lightning Fast Websites (for Twin Cities .NET User Group)
strommen
 
Platform Cache
Salesforce Developers
 
Ad

More from ArrrrCamp (15)

PDF
Arrrrcamp Radiant Intro
ArrrrCamp
 
KEY
Ruby 1.9 And Rails 3.0
ArrrrCamp
 
PDF
Metaprogramming + Ds Ls
ArrrrCamp
 
PDF
Rubyandrails
ArrrrCamp
 
PDF
Nanoc
ArrrrCamp
 
PDF
Git
ArrrrCamp
 
PDF
Radiant
ArrrrCamp
 
PDF
Mistakes
ArrrrCamp
 
PDF
Railsservers
ArrrrCamp
 
PDF
Prawn
ArrrrCamp
 
PDF
Testing
ArrrrCamp
 
PDF
Validation
ArrrrCamp
 
PDF
Cucumber
ArrrrCamp
 
PDF
Ruby and Rails Basics
ArrrrCamp
 
PDF
Advanced Radiant
ArrrrCamp
 
Arrrrcamp Radiant Intro
ArrrrCamp
 
Ruby 1.9 And Rails 3.0
ArrrrCamp
 
Metaprogramming + Ds Ls
ArrrrCamp
 
Rubyandrails
ArrrrCamp
 
Nanoc
ArrrrCamp
 
Radiant
ArrrrCamp
 
Mistakes
ArrrrCamp
 
Railsservers
ArrrrCamp
 
Prawn
ArrrrCamp
 
Testing
ArrrrCamp
 
Validation
ArrrrCamp
 
Cucumber
ArrrrCamp
 
Ruby and Rails Basics
ArrrrCamp
 
Advanced Radiant
ArrrrCamp
 

Recently uploaded (20)

PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
July Patch Tuesday
Ivanti
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Python basic programing language for automation
DanialHabibi2
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 

Caching your rails application