SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante 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
 

Semelhante 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

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
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
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
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
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
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...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
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
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

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