SlideShare une entreprise Scribd logo
1  sur  30
MEMCACHED: WHAT IS IT
AND WHAT DOES IT DO?
             Brian Moon
            dealnews.com
     http://brian.moonspot.net/
@BRIANLMOON
• Senior Web Engineer for
    dealnews.com
• Founder and lead developer of
    Phorum
•   Memcached community member
•   Gearmand contributor
•   PHP internals contributor
•   I used PHP/FI
WHAT IS A CACHE?
WHAT IS A CACHE?

   "1 a: a hiding place especially for
concealing and preserving provisions or
implements b: a secure place of storage"


        http://www.merriam-webster.com/dictionary/cache
http://www.flickr.com/photos/simonov/479658875/
WHAT IS A CACHE?
   "...a component that improves performance by
transparently storing data such that future requests for
  that data can be served faster. The data that is stored
     within a cache might be values that have been
computed earlier or duplicates of original values that
are stored elsewhere. If requested data is contained in
   the cache (cache hit), this request can be served by
 simply reading the cache, which is comparably faster.
       Otherwise (cache miss), the data has to be
   recomputed or fetched from its original storage
         location, which is comparably slower."
                 http://en.wikipedia.org/wiki/Cache
WHAT IS A CACHE?
   "...a component that improves performance by
transparently storing data such that future requests for
  that data can be served faster. The data that is stored
     within a cache might be values that have been
computed earlier or duplicates of original values that
are stored elsewhere. If requested data is contained in
   the cache (cache hit), this request can be served by
 simply reading the cache, which is comparably faster.
       Otherwise (cache miss), the data has to be
   recomputed or fetched from its original storage
         location, which is comparably slower."
                 http://en.wikipedia.org/wiki/Cache
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
CLIENT OPTIONS
•   C/C++ - libmemcached
•   PHP - PECL/memcached
•   Perl - Cache::Memcached
•   Python - python-memcached / Python libmemcached
•   Ruby - Ruby MemCache (per Google)
•   Java - spymemcached
•   Plus MySQL UDF, .NET, C#, Erlang, Lua, and more
SIMPLE PHP EXAMPLE
$MEMCACHE = new Memcached();
$MEMCACHE->addServer(“192.168.0.1”, 11211);
$MEMCACHE->addServer(“192.168.0.2”, 11211);

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

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

echo $mydata;
http://www.flickr.com/photos/tomharpel/1748935/




Where is my data stored?
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”
WHERE IS MY DATA?

               Traditional

server = servers[hash(key) % servers.length]
               (eenie meenie miney moe)
WHERE IS MY DATA?
“Consistent”
Each server is allocated
LOTS of numbers on a
“wheel”. The key is
hashed to a number in
that range and the
server assigned the
closest number is used.
Adding/removing
servers from the list      http://www.flickr.com/photos/k-bot/2614389196/

results in less key
reassignment.
What can I store?
                                                How big can it be?




http://www.flickr.com/photos/hshap/469025786/
WHAT CAN I STORE?

•   Server stores blobs of binary data
•   Most clients will serialize non-string 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.
• Some clients may normalize keys for you. But, don’t
    count on it.
DATA SIZE MATTERS
• Maximum size for one item is 1MB (until recently)
• Some clients support compression
• 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.
&E
                                                      vict
                                                          ion
                                                                s



http://www.flickr.com/photos/aussiegall/322980012/
EVICTION AND EXPIRATION
• Expiration time can be expressed
  as seconds from now or as an
  absolute epoch time.
• Items are not removed from
  memory when they expire
• Items are evicted when newer
  items need to be stored
• Least Recently Used (LRU)
  determines what is evicted
• Eviction is done per slab          http://www.flickr.com/photos/bitchcakes/4410181958/
How do I know it is working?




http://www.flickr.com/photos/carolinadoug/3932117107/
HOW WELL IS IT WORKING?
HOW WELL IS IT WORKING?




    STAT   uptime 9207843
    STAT   cmd_get 66421687
    STAT   cmd_set 10640419
    STAT   get_hits 66421687     84%
    STAT   get_misses 12360549   hit rate

    STAT   evictions 0
HOW WELL IS IT WORKING?
 • Graph stats from memcached using Cacti/Ganglia, etc.
 • Key stats:
   • Hits/Misses
   • Gets/Sets
   • Evictions
 • Cacti Templates:
   • http://dealnews.com/developers/
   • http://code.google.com/p/mysql-cacti-templates/
There are some things
you think you want to
 do, but you can’t do
them and/or shouldn’t
      do them.


                        http://www.flickr.com/photos/magdalar/4241254141/
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!
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
• Maybe try Tokyo Tyrant, MongoDB or another
  “NOSQL” key/data store
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
• There have been patches, but they never performed
  well.
MORE THINGS NOT TO DO

•   Use memcached as a locking daemon
•   Use memcached to store data that can’t go away
•   Don’t use it to try and speed up your intranet
•   Store complex data types that the clients have to
    serialize or unserialize
• Complain on the mailing list that you can’t do any of the
    things listed above. =)
QUEUES



JUST DON’T OK?
   see dormando in #memcached on freenode
REFERENCES

• http://code.google.com/p/memcached/
• http://code.google.com/p/memcached/wiki/Clients

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

Contenu connexe

Tendances

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
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라Park Chunduck
 
Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009NorthScale
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnishschoefmax
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimizationAlmog Baku
 
High performance WordPress
High performance WordPressHigh performance WordPress
High performance WordPressMikel King
 
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
 
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
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningTimothy Wood
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 

Tendances (20)

Memcached
MemcachedMemcached
Memcached
 
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
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라
 
Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimization
 
High performance WordPress
High performance WordPressHigh performance WordPress
High performance WordPress
 
Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)Simple Site Speed Improvements (SMX 2010)
Simple Site Speed Improvements (SMX 2010)
 
Presentation1
Presentation1Presentation1
Presentation1
 
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
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & Tuning
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Optimizing wp
Optimizing wpOptimizing wp
Optimizing wp
 

Similaire à Memcached: What is it and what does it do?

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
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Jason Ragsdale
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails applicationArrrrCamp
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik Brandsberg
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik BrandsbergScaling SQL Write-Master Database Clusters With Redis Labs: Erik Brandsberg
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik BrandsbergRedis Labs
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core HacksDaniel Niedergesäß
 
Accelerating Rails with edge caching
Accelerating Rails with edge cachingAccelerating Rails with edge caching
Accelerating Rails with edge cachingMichael May
 
Managing Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using ElasticsearchManaging Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using ElasticsearchJoe Alex
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Jess Coburn
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012jonswar
 
Design for Scale / Surge 2010
Design for Scale / Surge 2010Design for Scale / Surge 2010
Design for Scale / Surge 2010Christopher Brown
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeFastly
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeMichael May
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ Docker, Inc.
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your WebsiteAcquia
 

Similaire à Memcached: What is it and what does it do? (20)

Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
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
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails application
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik Brandsberg
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik BrandsbergScaling SQL Write-Master Database Clusters With Redis Labs: Erik Brandsberg
Scaling SQL Write-Master Database Clusters With Redis Labs: Erik Brandsberg
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core Hacks
 
Accelerating Rails with edge caching
Accelerating Rails with edge cachingAccelerating Rails with edge caching
Accelerating Rails with edge caching
 
Managing Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using ElasticsearchManaging Security At 1M Events a Second using Elasticsearch
Managing Security At 1M Events a Second using Elasticsearch
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012
 
Design for Scale / Surge 2010
Design for Scale / Surge 2010Design for Scale / Surge 2010
Design for Scale / Surge 2010
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the Edge
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the Edge
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 

Dernier

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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?
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Memcached: What is it and what does it do?

  • 1. MEMCACHED: WHAT IS IT AND WHAT DOES IT DO? Brian Moon dealnews.com http://brian.moonspot.net/
  • 2. @BRIANLMOON • Senior Web Engineer for dealnews.com • Founder and lead developer of Phorum • Memcached community member • Gearmand contributor • PHP internals contributor • I used PHP/FI
  • 3. WHAT IS A CACHE?
  • 4. WHAT IS A CACHE? "1 a: a hiding place especially for concealing and preserving provisions or implements b: a secure place of storage" http://www.merriam-webster.com/dictionary/cache
  • 6. WHAT IS A CACHE? "...a component that improves performance by transparently storing data such that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere. If requested data is contained in the cache (cache hit), this request can be served by simply reading the cache, which is comparably faster. Otherwise (cache miss), the data has to be recomputed or fetched from its original storage location, which is comparably slower." http://en.wikipedia.org/wiki/Cache
  • 7. WHAT IS A CACHE? "...a component that improves performance by transparently storing data such that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere. If requested data is contained in the cache (cache hit), this request can be served by simply reading the cache, which is comparably faster. Otherwise (cache miss), the data has to be recomputed or fetched from its original storage location, which is comparably slower." http://en.wikipedia.org/wiki/Cache
  • 8. 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
  • 9. CLIENT OPTIONS • C/C++ - libmemcached • PHP - PECL/memcached • Perl - Cache::Memcached • Python - python-memcached / Python libmemcached • Ruby - Ruby MemCache (per Google) • Java - spymemcached • Plus MySQL UDF, .NET, C#, Erlang, Lua, and more
  • 10. SIMPLE PHP EXAMPLE $MEMCACHE = new Memcached(); $MEMCACHE->addServer(“192.168.0.1”, 11211); $MEMCACHE->addServer(“192.168.0.2”, 11211); $mydata = $MEMCACHE->get(“mydata”); if($mydata === false){ $mydata = generate_mydata(); $MEMCACHE->set(“mydata”, $mydata, 86400); } echo $mydata;
  • 12. 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”
  • 13. WHERE IS MY DATA? Traditional server = servers[hash(key) % servers.length] (eenie meenie miney moe)
  • 14. WHERE IS MY DATA? “Consistent” Each server is allocated LOTS of numbers on a “wheel”. The key is hashed to a number in that range and the server assigned the closest number is used. Adding/removing servers from the list http://www.flickr.com/photos/k-bot/2614389196/ results in less key reassignment.
  • 15. What can I store? How big can it be? http://www.flickr.com/photos/hshap/469025786/
  • 16. WHAT CAN I STORE? • Server stores blobs of binary data • Most clients will serialize non-string 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. • Some clients may normalize keys for you. But, don’t count on it.
  • 17. DATA SIZE MATTERS • Maximum size for one item is 1MB (until recently) • Some clients support compression • 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.
  • 18. &E vict ion s http://www.flickr.com/photos/aussiegall/322980012/
  • 19. EVICTION AND EXPIRATION • Expiration time can be expressed as seconds from now or as an absolute epoch time. • Items are not removed from memory when they expire • Items are evicted when newer items need to be stored • Least Recently Used (LRU) determines what is evicted • Eviction is done per slab http://www.flickr.com/photos/bitchcakes/4410181958/
  • 20. How do I know it is working? http://www.flickr.com/photos/carolinadoug/3932117107/
  • 21. HOW WELL IS IT WORKING?
  • 22. HOW WELL IS IT WORKING? STAT uptime 9207843 STAT cmd_get 66421687 STAT cmd_set 10640419 STAT get_hits 66421687 84% STAT get_misses 12360549 hit rate STAT evictions 0
  • 23. HOW WELL IS IT WORKING? • Graph stats from memcached using Cacti/Ganglia, etc. • Key stats: • Hits/Misses • Gets/Sets • Evictions • Cacti Templates: • http://dealnews.com/developers/ • http://code.google.com/p/mysql-cacti-templates/
  • 24. There are some things you think you want to do, but you can’t do them and/or shouldn’t do them. http://www.flickr.com/photos/magdalar/4241254141/
  • 25. 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!
  • 26. 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 • Maybe try Tokyo Tyrant, MongoDB or another “NOSQL” key/data store
  • 27. 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 • There have been patches, but they never performed well.
  • 28. MORE THINGS NOT TO DO • Use memcached as a locking daemon • Use memcached to store data that can’t go away • Don’t use it to try and speed up your intranet • Store complex data types that the clients have to serialize or unserialize • Complain on the mailing list that you can’t do any of the things listed above. =)
  • 29. QUEUES JUST DON’T OK? see dormando in #memcached on freenode

Notes de l'éditeur