SlideShare una empresa de Scribd logo
1 de 55
Descargar para leer sin conexión
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, ...)

Más contenido relacionado

La actualidad más candente

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

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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...
 

Caching your rails application