SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
MEMCACHED: WHAT IS IT
                AND WHAT DOES IT DO?
                                        Brian Moon
                                       dealnews.com
                                http://brian.moonspot.net/




Wednesday, September 30, 2009
@BRIANLMOON
                • Senior Web Engineer for dealnews.com
                  • Survived a 2006 Yahoo front page link
                • Founder and lead developer of Phorum
                • Memcached community member
                • Gearmand contributor
                • PHP internals contributor
                • I used PHP/FI

Wednesday, September 30, 2009
WHAT IS MEMCACHED?
       memcached is a high-performance, distributed
       memory object caching system, generic in nature, but
       intended for use in speeding up dynamic web
       applications by alleviating database load.
                •      Dumb daemon
                •      It is a generic key/data storage system
                •      Uses libevent and epoll/kqueue
                •      Caches data in memory
                •      Cache is distributed by the smart clients

Wednesday, September 30, 2009
PHP OPTIONS
                • PECL/memcache
                  • Mature
                  • Standalone
                  • More hand holding
                • PECL/memcached
                  • Built on libmemcached
                  • More of a raw API
                  • Has more features
Wednesday, September 30, 2009
SIMPLE PHP EXAMPLE
   $MEMCACHE = new Memcache();
   $MEMCACHE->addServer(“192.168.0.1”);
   $MEMCACHE->addServer(“192.168.0.2”);

   $mydata = $MEMCACHE->get(“mydata”);

   if($mydata === false){
       $mydata = generate_mydata();
       $MEMCACHE->set(“mydata”, $mydata,
           MEMCACHE_COMPRESSED,
           86400);
   }
   echo $mydata;

Wednesday, September 30, 2009
WHERE IS MY DATA?
                • The client (not server) uses a hashing algorithm to
                       determine the storage server
                •      Data is sent to only one server
                •      Servers do not share data
                •      Data is not replicated
                •      Two hashing algorithms possible:
                       • Traditional
                       • “Consistent”

Wednesday, September 30, 2009
WHERE IS MY DATA?
                • Both hash the key and use the result to choose a server.
                • Traditional hashing uses the forumla:
                  • hash % num_servers
                  • Resulting number determines the server used.
                • In “Consistent” hashing, each server is allocated LOTS of
                       slots and a key is hashed and to a number. The closest
                       slot to that number is the server.
                       • Adding/removing servers from the list results in less
                                key reassignment.

Wednesday, September 30, 2009
WHAT CAN I STORE?
                •      Server stores blobs of data up to 1MB
                •      PHP extensions will serialize non-scalar data
                •      Keys are limited to 250 bytes in length
                •      Keys can not contain spaces or “high” characters. Stick
                       with letters, numbers, _ and you are pretty safe.
                • PECL/memcache will convert keys for you.
                • PECL/memcached will returns false and an additional
                       method must be used to find out why the set failed.


Wednesday, September 30, 2009
DATA SIZE MATTERS
                • Maximum size for one item is 1MB
                • Both clients support compression, neither by default
                • Data is stored in slabs based on size
                  • Lots of items of the same size is not optimal
                  • Slab size can be customized
                  • May not be able to store items when it appears
                                there is “free” memory
                       • Data can be evicted sooner than expected.

Wednesday, September 30, 2009
EVICTION AND EXPIRATION
                • Expiration time can be expressed as seconds from now
                       or as an absolute epoch time.
                       • Values > 30 days are assumed to be an absolute time
                       • Items are not removed from memory when they
                                expire
                • Items are evicted when newer items need to be stored
                  • Least Recenty Used (LRU) determines what is
                                evicted
                       • Eviction is done per slab
Wednesday, September 30, 2009
HOW WELL IS IT WORKING?
                • Graph stats from memcached using Cacti/Ganglia, etc.
                • Key stats:          STAT cmd_get 4507207
                  • Hits/Misses       STAT cmd_set 1098829
                                      STAT get_hits 3221599
                  • Gets/Sets         STAT get_misses 1285608
                                      STAT evictions 0
                  • Evictions
                  • Cacti Templates: http://dealnews.com/developers/



Wednesday, September 30, 2009
HOW DO I SEE THE CACHE?

                • You have no way to see the cached data.
                • You probably don’t need to see it.
                • For memcached to tell you, it would freeze your entire
                       caching system
                • There are debug ways to see.
                • DO NOT COMPILE PRODUCTION WITH DEBUG
                       BECAUSE YOU ARE A CONTROL FREAK!



Wednesday, September 30, 2009
HOW DO I BACK IT UP?


                •You don’t!
                • If you application requires that, you are using it wrong
                • It is a cache, not a data storage system




Wednesday, September 30, 2009
NAMESPACES & TAGGING

                • There is no concept of namespaces or tagging built in
                       to memcached
                • You can simulate them with an extra key storage
                • See the FAQ for an example of simulated namespaces
                • This of course means there is no mass delete in
                       memcached



Wednesday, September 30, 2009
ADVANCED TIPS
                • Use multi-gets to increase performance
                  • PECL/memcache takes an array of keys to get()
                  • PECL/memcached has a separate method
                • Use the binary protocol in PECL/memcached
                • Group keys with a master key
                • Use a cache hierarchy
                  • GLOBALS + APC + memcached

Wednesday, September 30, 2009
REFERENCES

                • http://code.google.com/p/memcached/
                • http://pecl.php.net/package/memcache
                • http://pecl.php.net/package/memcached

                • http://brian.moonspot.net/
                • http://dealnews.com/developers/


Wednesday, September 30, 2009

Más contenido relacionado

La actualidad más candente

Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 
Moxi - Memcached Proxy
Moxi - Memcached ProxyMoxi - Memcached Proxy
Moxi - Memcached ProxyNorthScale
 
Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)Ralf Schwoebel
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
High Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlHigh Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlJoomla!Days Netherlands
 
Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009NorthScale
 
High performance WordPress
High performance WordPressHigh performance WordPress
High performance WordPressMikel King
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimizationAlmog Baku
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnishschoefmax
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningTimothy Wood
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal SitesAbayomi Ayoola
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라Park Chunduck
 
How to reduce database load using Memcache
How to reduce database load using MemcacheHow to reduce database load using Memcache
How to reduce database load using Memcachevaluebound
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 

La actualidad más candente (20)

Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 
Moxi - Memcached Proxy
Moxi - Memcached ProxyMoxi - Memcached Proxy
Moxi - Memcached Proxy
 
Presentation1
Presentation1Presentation1
Presentation1
 
Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
High Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlHigh Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nl
 
Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009
 
High performance WordPress
High performance WordPressHigh performance WordPress
High performance WordPress
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimization
 
Memcached
MemcachedMemcached
Memcached
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & Tuning
 
23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal Sites
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라
 
How to reduce database load using Memcache
How to reduce database load using MemcacheHow to reduce database load using Memcache
How to reduce database load using Memcache
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Optimizing wp
Optimizing wpOptimizing wp
Optimizing wp
 

Similar a Memcached: What is it and what does it do? (PHP Version)

MySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewMySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewSachin Khosla
 
High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2ScribbleLive
 
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up Data
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up DataWebinar: MongoDB Management Service (MMS): Session 02 - Backing up Data
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up DataMongoDB
 
Content Management Selection and Strategy
Content Management Selection and StrategyContent Management Selection and Strategy
Content Management Selection and StrategyIvo Jansch
 
Ibuildings Cms Talk
Ibuildings Cms TalkIbuildings Cms Talk
Ibuildings Cms Talkdean1985
 
Design for Scale / Surge 2010
Design for Scale / Surge 2010Design for Scale / Surge 2010
Design for Scale / Surge 2010Christopher Brown
 
Investigate TempDB Like Sherlock Holmes
Investigate TempDB Like Sherlock HolmesInvestigate TempDB Like Sherlock Holmes
Investigate TempDB Like Sherlock HolmesRichard Douglas
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Norberto Leite
 
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...In-Memory Computing Summit
 
Plugin Memcached%20 Study
Plugin Memcached%20 StudyPlugin Memcached%20 Study
Plugin Memcached%20 StudyLiu Lizhi
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines	Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines MongoDB
 
Memcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav JainMemcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav JainDrupal Camp Delhi
 
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 SeamsConcentric Sky
 
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)Julien SIMON
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage SystemsSATOSHI TAGOMORI
 
Big Memory for HPC
Big Memory for HPCBig Memory for HPC
Big Memory for HPCMemVerge
 

Similar a Memcached: What is it and what does it do? (PHP Version) (20)

Perf tuning2
Perf tuning2Perf tuning2
Perf tuning2
 
All The Little Pieces
All The Little PiecesAll The Little Pieces
All The Little Pieces
 
MySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of viewMySQL Optimization from a Developer's point of view
MySQL Optimization from a Developer's point of view
 
High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2
 
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up Data
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up DataWebinar: MongoDB Management Service (MMS): Session 02 - Backing up Data
Webinar: MongoDB Management Service (MMS): Session 02 - Backing up Data
 
Content Management Selection and Strategy
Content Management Selection and StrategyContent Management Selection and Strategy
Content Management Selection and Strategy
 
Ibuildings Cms Talk
Ibuildings Cms TalkIbuildings Cms Talk
Ibuildings Cms Talk
 
Design for Scale / Surge 2010
Design for Scale / Surge 2010Design for Scale / Surge 2010
Design for Scale / Surge 2010
 
Investigate TempDB Like Sherlock Holmes
Investigate TempDB Like Sherlock HolmesInvestigate TempDB Like Sherlock Holmes
Investigate TempDB Like Sherlock Holmes
 
Performance Strategies
Performance StrategiesPerformance Strategies
Performance Strategies
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0
 
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
 
Memcached
MemcachedMemcached
Memcached
 
Plugin Memcached%20 Study
Plugin Memcached%20 StudyPlugin Memcached%20 Study
Plugin Memcached%20 Study
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines	Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines
 
Memcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav JainMemcache and Drupal - Vaibhav Jain
Memcache and Drupal - Vaibhav Jain
 
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
 
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)
AIM361 Optimizing machine learning models with Amazon SageMaker (December 2019)
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Big Memory for HPC
Big Memory for HPCBig Memory for HPC
Big Memory for HPC
 

Último

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 organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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.pptxMalak Abu Hammad
 
[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.pdfhans926745
 
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 textsMaria Levchenko
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Último (20)

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
[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
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

Memcached: What is it and what does it do? (PHP Version)

  • 1. MEMCACHED: WHAT IS IT AND WHAT DOES IT DO? Brian Moon dealnews.com http://brian.moonspot.net/ Wednesday, September 30, 2009
  • 2. @BRIANLMOON • Senior Web Engineer for dealnews.com • Survived a 2006 Yahoo front page link • Founder and lead developer of Phorum • Memcached community member • Gearmand contributor • PHP internals contributor • I used PHP/FI Wednesday, September 30, 2009
  • 3. WHAT IS MEMCACHED? memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. • Dumb daemon • It is a generic key/data storage system • Uses libevent and epoll/kqueue • Caches data in memory • Cache is distributed by the smart clients Wednesday, September 30, 2009
  • 4. PHP OPTIONS • PECL/memcache • Mature • Standalone • More hand holding • PECL/memcached • Built on libmemcached • More of a raw API • Has more features Wednesday, September 30, 2009
  • 5. SIMPLE PHP EXAMPLE $MEMCACHE = new Memcache(); $MEMCACHE->addServer(“192.168.0.1”); $MEMCACHE->addServer(“192.168.0.2”); $mydata = $MEMCACHE->get(“mydata”); if($mydata === false){ $mydata = generate_mydata(); $MEMCACHE->set(“mydata”, $mydata, MEMCACHE_COMPRESSED, 86400); } echo $mydata; Wednesday, September 30, 2009
  • 6. WHERE IS MY DATA? • The client (not server) uses a hashing algorithm to determine the storage server • Data is sent to only one server • Servers do not share data • Data is not replicated • Two hashing algorithms possible: • Traditional • “Consistent” Wednesday, September 30, 2009
  • 7. WHERE IS MY DATA? • Both hash the key and use the result to choose a server. • Traditional hashing uses the forumla: • hash % num_servers • Resulting number determines the server used. • In “Consistent” hashing, each server is allocated LOTS of slots and a key is hashed and to a number. The closest slot to that number is the server. • Adding/removing servers from the list results in less key reassignment. Wednesday, September 30, 2009
  • 8. WHAT CAN I STORE? • Server stores blobs of data up to 1MB • PHP extensions will serialize non-scalar data • Keys are limited to 250 bytes in length • Keys can not contain spaces or “high” characters. Stick with letters, numbers, _ and you are pretty safe. • PECL/memcache will convert keys for you. • PECL/memcached will returns false and an additional method must be used to find out why the set failed. Wednesday, September 30, 2009
  • 9. DATA SIZE MATTERS • Maximum size for one item is 1MB • Both clients support compression, neither by default • Data is stored in slabs based on size • Lots of items of the same size is not optimal • Slab size can be customized • May not be able to store items when it appears there is “free” memory • Data can be evicted sooner than expected. Wednesday, September 30, 2009
  • 10. EVICTION AND EXPIRATION • Expiration time can be expressed as seconds from now or as an absolute epoch time. • Values > 30 days are assumed to be an absolute time • Items are not removed from memory when they expire • Items are evicted when newer items need to be stored • Least Recenty Used (LRU) determines what is evicted • Eviction is done per slab Wednesday, September 30, 2009
  • 11. HOW WELL IS IT WORKING? • Graph stats from memcached using Cacti/Ganglia, etc. • Key stats: STAT cmd_get 4507207 • Hits/Misses STAT cmd_set 1098829 STAT get_hits 3221599 • Gets/Sets STAT get_misses 1285608 STAT evictions 0 • Evictions • Cacti Templates: http://dealnews.com/developers/ Wednesday, September 30, 2009
  • 12. HOW DO I SEE THE CACHE? • You have no way to see the cached data. • You probably don’t need to see it. • For memcached to tell you, it would freeze your entire caching system • There are debug ways to see. • DO NOT COMPILE PRODUCTION WITH DEBUG BECAUSE YOU ARE A CONTROL FREAK! Wednesday, September 30, 2009
  • 13. HOW DO I BACK IT UP? •You don’t! • If you application requires that, you are using it wrong • It is a cache, not a data storage system Wednesday, September 30, 2009
  • 14. NAMESPACES & TAGGING • There is no concept of namespaces or tagging built in to memcached • You can simulate them with an extra key storage • See the FAQ for an example of simulated namespaces • This of course means there is no mass delete in memcached Wednesday, September 30, 2009
  • 15. ADVANCED TIPS • Use multi-gets to increase performance • PECL/memcache takes an array of keys to get() • PECL/memcached has a separate method • Use the binary protocol in PECL/memcached • Group keys with a master key • Use a cache hierarchy • GLOBALS + APC + memcached Wednesday, September 30, 2009
  • 16. REFERENCES • http://code.google.com/p/memcached/ • http://pecl.php.net/package/memcache • http://pecl.php.net/package/memcached • http://brian.moonspot.net/ • http://dealnews.com/developers/ Wednesday, September 30, 2009