SlideShare a Scribd company logo
1 of 24
Download to read offline
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

More Related Content

What's hot

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
 

What's hot (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?
 

Viewers also liked

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
 

Viewers also liked (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)
 

Similar to 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 09
Google DevFest 09Google DevFest 09
Google DevFest 09Eze Torres
 

Similar to 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 09
Google DevFest 09Google DevFest 09
Google DevFest 09
 

Recently uploaded

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 

Recently uploaded (20)

Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 

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

Editor's Notes