SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Caching,
                 Memcached,
                 and Rails

                 Mike Perham
                 http://mikeperham.com

Wednesday, March 25, 2009
Me	


                  Maintainer of memcache-client, shipped with Rails

                  Hardcore performance nerd




Wednesday, March 25, 2009
Performance


                  Let me Tell you a Story...




Wednesday, March 25, 2009
Performance Tuning

                  Remove unnecessary Functionality

                  Tune necessary Functionality

                  ONLY THEN, add caching last

                  ALWAYS track before/after timings




Wednesday, March 25, 2009
Caching

                  Cache the results of expensive operations

                  Why is this memoization dumb?




Wednesday, March 25, 2009
Why Dumb?

                            SCALABILITY!
                            FRESHNESS!



Wednesday, March 25, 2009
Rails
                  Built in support for memcached since Rails 2.1

                  config/environments/production.rb:




Wednesday, March 25, 2009
Request
                            Varnish   Apache     Rails     DB




                                               Memcached



                  Standard Toolset for Rails 2.3

                  Further == Slower



Wednesday, March 25, 2009
Caching Mechanisms

                  HTTP Proxy
                               FASTER
                  Page

                  Action

                  Fragment
                               SLOWER
                  Object



Wednesday, March 25, 2009
HTTP Proxy


                  HTTP/URL caching with Varnish

                       Expires, Etag, Cache-Control headers

                  5-10k req/sec!




Wednesday, March 25, 2009
Page Caching	


                  ERB --> Static HTML

                  Uh oh, uses the filesystem!

                  Apache = 1-5k req/sec




Wednesday, March 25, 2009
Action Caching


                  Runs filters (e.g. authorization)

                  Can use any cache strategy

                       File, memory, memcached




Wednesday, March 25, 2009
Fragment Caching


                  Parts of the page are unique per user

                  Fragment cache the various UI boxes

                  Dynamically assemble HTML from the cache




Wednesday, March 25, 2009
Object Caching

                  Built-in AR support for “smart” keys

                       Rails.cache.fetch(post.cache_key) { expensive_calc(post) }

                       “#{table_name}/#{self.id}-#{self.updated_at.to_i}”

                  Support for complex dependencies




Wednesday, March 25, 2009
Expiration
                  “There are only two hard things in Computer
                  Science: naming and cache invalidation”

                  Explicit
                       expire_page :controller => ‘users’, :action => ‘index’

                       expire_action :controller => ‘users’, :action => ‘index’

                       Rails.cache.delete(‘key’)


                  Observers


Wednesday, March 25, 2009
Expiration (Cont’d)
                  Time-based
                        Rails.cache.fetch(‘key’, :expires_in => 1.hour) { ... }

                        expires_in(2.hours) # sets page’s HTTP max-age attribute


                  Versioning
                        Rails.cache.fetch(user.cache_key) { ... }




Wednesday, March 25, 2009
Memcached

                  Giant Hash of Fixed Size

                  Time-based expiration

                  LRU eviction

                  Operations: GET, SET, APPEND, INCR, CAS

                  Limited to 1MB per value, 250 chars per key



Wednesday, March 25, 2009
Facebook


                  100s of servers w/ 28TB of RAM

                  5 billion page views/day

                  400k req/sec from memcached




Wednesday, March 25, 2009
Performance




Wednesday, March 25, 2009
Mongrel + Nginx
                                         Varnish

                                         Nginx

                                         WEB1

                                                   M1     M2
                            M1      M2


                        Memcached                  Memcached


                                 APP1                   APP2

Wednesday, March 25, 2009
Apache + Passenger
                                           Varnish

                                           HAProxy


                                           WEB1

                             Memcached                         Memcached
               Apache                                Apache


                    Rails          Rails              Rails          Rails


                            APP1                              APP2

Wednesday, March 25, 2009
Advanced


                  Spread your cache across a farm of memcached

                  Use the memcaches_page plugin

                  Use AJAX for user-specific widgets




Wednesday, March 25, 2009
Advice

                  Cache late in the development cycle, after tuning!

                  Memcached gives you time-based expiration,
                  versioning and multi-machine support.

                  Cache as early in the request as possible!


                            Varnish   Apache   Rails   DB




Wednesday, March 25, 2009
THANK YOU!
                            HTTP://MIKEPERHAM.COM
                             MPERHAM@GMAIL.COM

                                 QUESTIONS?




Wednesday, March 25, 2009

Weitere ähnliche Inhalte

Was ist angesagt?

Magento caching
Magento cachingMagento caching
Magento cachingYireo
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stackJohan Edstrom
 
Apache Tomcat 8 Application Server
Apache Tomcat 8 Application ServerApache Tomcat 8 Application Server
Apache Tomcat 8 Application Servermohamedmoharam
 
Vmware management-with-vcli-5.0
Vmware management-with-vcli-5.0Vmware management-with-vcli-5.0
Vmware management-with-vcli-5.0Sathishkumar A
 
How automated cloud infrastructure setups can help with Continuous Delivery
How automated cloud infrastructure setups can help with Continuous DeliveryHow automated cloud infrastructure setups can help with Continuous Delivery
How automated cloud infrastructure setups can help with Continuous DeliveryEdmund Siegfried Haselwanter
 
Tomcat Configuration (1)
Tomcat Configuration (1)Tomcat Configuration (1)
Tomcat Configuration (1)nazeer pasha
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clusteringgouthamrv
 
Empowering Next Generation Media
Empowering Next Generation MediaEmpowering Next Generation Media
Empowering Next Generation MediaRicardo Piccoli
 
Introduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationIntroduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationTomcat Expert
 
Next-Generation Best Practices for VMware and Storage
Next-Generation Best Practices for VMware and StorageNext-Generation Best Practices for VMware and Storage
Next-Generation Best Practices for VMware and StorageScott Lowe
 
Introduction of Tomcat
Introduction of TomcatIntroduction of Tomcat
Introduction of TomcatDebashis Nath
 
Living the Easy Life with Rules-Based Autonomic Database Clusters
Living the Easy Life with Rules-Based Autonomic Database ClustersLiving the Easy Life with Rules-Based Autonomic Database Clusters
Living the Easy Life with Rules-Based Autonomic Database ClustersLinas Virbalas
 
Deploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse FabricDeploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse Fabricdejanb
 
Where Does VMware Integration Occur?
Where Does VMware Integration Occur?Where Does VMware Integration Occur?
Where Does VMware Integration Occur?Scott Lowe
 

Was ist angesagt? (20)

Magento caching
Magento cachingMagento caching
Magento caching
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stack
 
OpenSolaris Web Stack MySQL BOF
OpenSolaris Web Stack MySQL BOFOpenSolaris Web Stack MySQL BOF
OpenSolaris Web Stack MySQL BOF
 
Apache Tomcat 8 Application Server
Apache Tomcat 8 Application ServerApache Tomcat 8 Application Server
Apache Tomcat 8 Application Server
 
Vmware management-with-vcli-5.0
Vmware management-with-vcli-5.0Vmware management-with-vcli-5.0
Vmware management-with-vcli-5.0
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
Hosting
HostingHosting
Hosting
 
How automated cloud infrastructure setups can help with Continuous Delivery
How automated cloud infrastructure setups can help with Continuous DeliveryHow automated cloud infrastructure setups can help with Continuous Delivery
How automated cloud infrastructure setups can help with Continuous Delivery
 
Tomcat Configuration (1)
Tomcat Configuration (1)Tomcat Configuration (1)
Tomcat Configuration (1)
 
Tomcat server
 Tomcat server Tomcat server
Tomcat server
 
Tomcat next
Tomcat nextTomcat next
Tomcat next
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clustering
 
Empowering Next Generation Media
Empowering Next Generation MediaEmpowering Next Generation Media
Empowering Next Generation Media
 
Introduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationIntroduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 Presentation
 
Next-Generation Best Practices for VMware and Storage
Next-Generation Best Practices for VMware and StorageNext-Generation Best Practices for VMware and Storage
Next-Generation Best Practices for VMware and Storage
 
Infrastructure as Code with Chef / Puppet
Infrastructure as Code with Chef / PuppetInfrastructure as Code with Chef / Puppet
Infrastructure as Code with Chef / Puppet
 
Introduction of Tomcat
Introduction of TomcatIntroduction of Tomcat
Introduction of Tomcat
 
Living the Easy Life with Rules-Based Autonomic Database Clusters
Living the Easy Life with Rules-Based Autonomic Database ClustersLiving the Easy Life with Rules-Based Autonomic Database Clusters
Living the Easy Life with Rules-Based Autonomic Database Clusters
 
Deploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse FabricDeploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse Fabric
 
Where Does VMware Integration Occur?
Where Does VMware Integration Occur?Where Does VMware Integration Occur?
Where Does VMware Integration Occur?
 

Andere mochten auch

Making and Breaking Web Services with Ruby
Making and Breaking Web Services with RubyMaking and Breaking Web Services with Ruby
Making and Breaking Web Services with Rubyerr
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010Mark Atwood
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScriptdanwrong
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQLKonstantin Gredeskoul
 
Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Konstantin Gredeskoul
 

Andere mochten auch (6)

Making and Breaking Web Services with Ruby
Making and Breaking Web Services with RubyMaking and Breaking Web Services with Ruby
Making and Breaking Web Services with Ruby
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
Caching
CachingCaching
Caching
 
Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)Enterprise Architectures with Ruby (and Rails)
Enterprise Architectures with Ruby (and Rails)
 

Ähnlich wie Caching, Memcached, and Rails Performance Tuning

Rails and Merb
Rails and MerbRails and Merb
Rails and Merbludoo
 
Plugin Memcached%20 Study
Plugin Memcached%20 StudyPlugin Memcached%20 Study
Plugin Memcached%20 StudyLiu Lizhi
 
Google html5 Tutorial
Google html5 TutorialGoogle html5 Tutorial
Google html5 Tutorialjobfan
 
Railswaycon 2009 - Summary
Railswaycon 2009 - SummaryRailswaycon 2009 - Summary
Railswaycon 2009 - Summarydaniel.mattes
 
Google Developer Days Brazil 2009 - Keynote
Google Developer Days Brazil 2009 -  KeynoteGoogle Developer Days Brazil 2009 -  Keynote
Google Developer Days Brazil 2009 - KeynotePatrick Chanezon
 
Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Corpeño
 
Google - Charla para CTOs
Google - Charla para CTOsGoogle - Charla para CTOs
Google - Charla para CTOsPalermo Valley
 
Why Ruby on Rails rocks from a .net developer eye
Why Ruby on Rails rocks from a .net developer eyeWhy Ruby on Rails rocks from a .net developer eye
Why Ruby on Rails rocks from a .net developer eyeAymeric Gaurat-Apelli
 
HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09mihaiionescu
 
intl me this, intl me that
intl me this, intl me thatintl me this, intl me that
intl me this, intl me thatAndrei Zmievski
 
Gear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with MemcachedGear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with MemcachedGear6
 
Nginx: From Russia With Love
Nginx: From Russia With LoveNginx: From Russia With Love
Nginx: From Russia With LoveEric Marden
 
Systems Integration in the Cloud Era, Kai Wähner MaibornWolff
Systems Integration in the Cloud Era, Kai Wähner MaibornWolffSystems Integration in the Cloud Era, Kai Wähner MaibornWolff
Systems Integration in the Cloud Era, Kai Wähner MaibornWolffCloudOps Summit
 
Using Q4M - a message queue storage engine for MySQL
Using Q4M - a message queue storage engine for MySQLUsing Q4M - a message queue storage engine for MySQL
Using Q4M - a message queue storage engine for MySQLKazuho Oku
 
090507.New Replication Features(2)
090507.New Replication Features(2)090507.New Replication Features(2)
090507.New Replication Features(2)liufabin 66688
 
Apache Sling - The whys and the hows
Apache Sling - The whys and the howsApache Sling - The whys and the hows
Apache Sling - The whys and the howsRobert Munteanu
 
Google Devfest 2009 Argentina - Keynote
Google Devfest 2009 Argentina - KeynoteGoogle Devfest 2009 Argentina - Keynote
Google Devfest 2009 Argentina - KeynotePatrick Chanezon
 

Ähnlich wie Caching, Memcached, and Rails Performance Tuning (20)

Alternative Databases
Alternative DatabasesAlternative Databases
Alternative Databases
 
Rails and Merb
Rails and MerbRails and Merb
Rails and Merb
 
Memcached
MemcachedMemcached
Memcached
 
Plugin Memcached%20 Study
Plugin Memcached%20 StudyPlugin Memcached%20 Study
Plugin Memcached%20 Study
 
Google html5 Tutorial
Google html5 TutorialGoogle html5 Tutorial
Google html5 Tutorial
 
Html5
Html5Html5
Html5
 
Railswaycon 2009 - Summary
Railswaycon 2009 - SummaryRailswaycon 2009 - Summary
Railswaycon 2009 - Summary
 
Google Developer Days Brazil 2009 - Keynote
Google Developer Days Brazil 2009 -  KeynoteGoogle Developer Days Brazil 2009 -  Keynote
Google Developer Days Brazil 2009 - Keynote
 
Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.
 
Google - Charla para CTOs
Google - Charla para CTOsGoogle - Charla para CTOs
Google - Charla para CTOs
 
Why Ruby on Rails rocks from a .net developer eye
Why Ruby on Rails rocks from a .net developer eyeWhy Ruby on Rails rocks from a .net developer eye
Why Ruby on Rails rocks from a .net developer eye
 
HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09
 
intl me this, intl me that
intl me this, intl me thatintl me this, intl me that
intl me this, intl me that
 
Gear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with MemcachedGear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with Memcached
 
Nginx: From Russia With Love
Nginx: From Russia With LoveNginx: From Russia With Love
Nginx: From Russia With Love
 
Systems Integration in the Cloud Era, Kai Wähner MaibornWolff
Systems Integration in the Cloud Era, Kai Wähner MaibornWolffSystems Integration in the Cloud Era, Kai Wähner MaibornWolff
Systems Integration in the Cloud Era, Kai Wähner MaibornWolff
 
Using Q4M - a message queue storage engine for MySQL
Using Q4M - a message queue storage engine for MySQLUsing Q4M - a message queue storage engine for MySQL
Using Q4M - a message queue storage engine for MySQL
 
090507.New Replication Features(2)
090507.New Replication Features(2)090507.New Replication Features(2)
090507.New Replication Features(2)
 
Apache Sling - The whys and the hows
Apache Sling - The whys and the howsApache Sling - The whys and the hows
Apache Sling - The whys and the hows
 
Google Devfest 2009 Argentina - Keynote
Google Devfest 2009 Argentina - KeynoteGoogle Devfest 2009 Argentina - Keynote
Google Devfest 2009 Argentina - Keynote
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Caching, Memcached, and Rails Performance Tuning

  • 1. Caching, Memcached, and Rails Mike Perham http://mikeperham.com Wednesday, March 25, 2009
  • 2. Me Maintainer of memcache-client, shipped with Rails Hardcore performance nerd Wednesday, March 25, 2009
  • 3. Performance Let me Tell you a Story... Wednesday, March 25, 2009
  • 4. Performance Tuning Remove unnecessary Functionality Tune necessary Functionality ONLY THEN, add caching last ALWAYS track before/after timings Wednesday, March 25, 2009
  • 5. Caching Cache the results of expensive operations Why is this memoization dumb? Wednesday, March 25, 2009
  • 6. Why Dumb? SCALABILITY! FRESHNESS! Wednesday, March 25, 2009
  • 7. Rails Built in support for memcached since Rails 2.1 config/environments/production.rb: Wednesday, March 25, 2009
  • 8. Request Varnish Apache Rails DB Memcached Standard Toolset for Rails 2.3 Further == Slower Wednesday, March 25, 2009
  • 9. Caching Mechanisms HTTP Proxy FASTER Page Action Fragment SLOWER Object Wednesday, March 25, 2009
  • 10. HTTP Proxy HTTP/URL caching with Varnish Expires, Etag, Cache-Control headers 5-10k req/sec! Wednesday, March 25, 2009
  • 11. Page Caching ERB --> Static HTML Uh oh, uses the filesystem! Apache = 1-5k req/sec Wednesday, March 25, 2009
  • 12. Action Caching Runs filters (e.g. authorization) Can use any cache strategy File, memory, memcached Wednesday, March 25, 2009
  • 13. Fragment Caching Parts of the page are unique per user Fragment cache the various UI boxes Dynamically assemble HTML from the cache Wednesday, March 25, 2009
  • 14. Object Caching Built-in AR support for “smart” keys Rails.cache.fetch(post.cache_key) { expensive_calc(post) } “#{table_name}/#{self.id}-#{self.updated_at.to_i}” Support for complex dependencies Wednesday, March 25, 2009
  • 15. Expiration “There are only two hard things in Computer Science: naming and cache invalidation” Explicit expire_page :controller => ‘users’, :action => ‘index’ expire_action :controller => ‘users’, :action => ‘index’ Rails.cache.delete(‘key’) Observers Wednesday, March 25, 2009
  • 16. Expiration (Cont’d) Time-based Rails.cache.fetch(‘key’, :expires_in => 1.hour) { ... } expires_in(2.hours) # sets page’s HTTP max-age attribute Versioning Rails.cache.fetch(user.cache_key) { ... } Wednesday, March 25, 2009
  • 17. Memcached Giant Hash of Fixed Size Time-based expiration LRU eviction Operations: GET, SET, APPEND, INCR, CAS Limited to 1MB per value, 250 chars per key Wednesday, March 25, 2009
  • 18. Facebook 100s of servers w/ 28TB of RAM 5 billion page views/day 400k req/sec from memcached Wednesday, March 25, 2009
  • 20. Mongrel + Nginx Varnish Nginx WEB1 M1 M2 M1 M2 Memcached Memcached APP1 APP2 Wednesday, March 25, 2009
  • 21. Apache + Passenger Varnish HAProxy WEB1 Memcached Memcached Apache Apache Rails Rails Rails Rails APP1 APP2 Wednesday, March 25, 2009
  • 22. Advanced Spread your cache across a farm of memcached Use the memcaches_page plugin Use AJAX for user-specific widgets Wednesday, March 25, 2009
  • 23. Advice Cache late in the development cycle, after tuning! Memcached gives you time-based expiration, versioning and multi-machine support. Cache as early in the request as possible! Varnish Apache Rails DB Wednesday, March 25, 2009
  • 24. THANK YOU! HTTP://MIKEPERHAM.COM MPERHAM@GMAIL.COM QUESTIONS? Wednesday, March 25, 2009

Hinweis der Redaktion