SlideShare uma empresa Scribd logo
1 de 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/

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
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라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
 

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

Semelhante a 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
 

Semelhante a 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
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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

Notas do Editor