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

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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