SlideShare a Scribd company logo
1 of 27
Download to read offline
Creating High Availability Services for Your
Memcached Environment
Presented by:
         Bill Takacs – Director, Product Management


25 August 2009
Agenda
     • Overview of Memcached


     • High Availability defined


     • Why HA Memcached


     • Options for HA Memcached


     • Gear6 Solution



2 : Copyright 2009 Gear6 Inc.
Memcached

             “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”
                                              Ref: http://www.danga.com/memcached/

     • Big hash table

     • Created by Danga Interactive for Live Journal

     • Significantly reduced database load

     • Perfect for web sites with high database load

     • In use by Facebook, Twitter, MyYearBook, others

3 : Copyright 2009 Gear6 Inc.
More on Memcached

     • Takes advantage of available DRAM

     • Open source

     • Distributed under BSD license

     • Server - Current version is 1.4
           » http://www.danga.com/memcached/download.bml

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


4 : Copyright 2009 Gear6 Inc.
How Does Memcached Work?

                                • Client - Server

                                • Hash Function

                                • Memcached
                                  » Two stage
                                  » Key / value pair




5 : Copyright 2009 Gear6 Inc.
Memcached Server

     • Slab allocator

     • Libevent based

     • Simple Protocol (no xml)

     • Server has internal hash table

     • Servers are dumb – they don’t know about each other




6 : Copyright 2009 Gear6 Inc.
Memcached Server

     • Limits
           » Key size = (250 bytes)
           » 1MB Limit
           » 32bit/64bit (maximum size of process)

     • LRU
           » Least recently accessed items are cycled out
           » One LRU exists per “slab class”
           » LRU “evictions” need not be common

     • Threads? Yes



7 : Copyright 2009 Gear6 Inc.
Memcached Clients

     • Client hashes key to server list

     • Serializes the object

     • Many client libraries

     • Authentication




8 : Copyright 2009 Gear6 Inc.
Commands

     • Storage commands:
           » Set / Add / Replace /
             Append / Prepend / CAS


     • Retrieval commands:
           » Get / Gets

     • Delete / increment /
       decrement

     • Stats


9 : Copyright 2009 Gear6 Inc.
High Availability
     • High availability: System
       design and implementation
       that ensures a certain
       absolute degree of
       operational continuity
       during a given measurement
       period.

     • Organizations
           » OpenSAF Foundation
           » SAFourm


     • HA for Memcache

10 : Copyright 2009 Gear6 Inc.
Key Concepts
     • Clustering

     • Failover

     • Replication




11 : Copyright 2009 Gear6 Inc.
The case for HA Memcache
     • What Memcache is NOT:
           »   A persistent data store
           »   A database
           »   Application specific
           »   Clustered
           »   A large object cache


     • The intent is if its not in cache hit the DB

     • Great when your site’s traffic is small

     • Let’s look at the evolution of a site


12 : Copyright 2009 Gear6 Inc.
The Beginning



                                            Web Servers


                                  MySQL
                                 Database




13 : Copyright 2009 Gear6 Inc.
Web traffic grows



                                            Memcached     Web Servers
                                                    Memcached
                                  MySQL                     Memcached
                                 Database




           Dynamic content:

           Result: Site slows down or worse site unavailable



14 : Copyright 2009 Gear6 Inc.
Add Memcached as traffic increases
                                                       Web Servers




                          MySQL
                                    Memcached
                         Database
                                           Memcached




      Increases performance but as the site grows so does Memcached




15 : Copyright 2009 Gear6 Inc.
Even more traffic

                                                                     Web Servers




                MySQL
               Databases


                                                 Memcached

                                                 Memcached   Memcache Server(s)
                                                 Memcached



                                 Reliance on memcached for performance




16 : Copyright 2009 Gear6 Inc.
Options for HA Memcached


     Not Many…

     • DIY

     • Or - Find a solution that leverages memcached that
         has high availability features




17 : Copyright 2009 Gear6 Inc.
Consistent Hashing
     • Why?

     • How does it work?

     • Where




18 : Copyright 2009 Gear6 Inc.
Consistent Hashing - Example
     • PHP – Flexihash – code.google.com/p/flexihash
     <?php
     $hash = new Flexihash();
     // bulk add
     $hash->addTargets(array('cache-1', 'cache-2', 'cache-3'));

     // simple lookup
     $hash->lookup('object-a'); // "cache-1"
     $hash->lookup('object-b'); // "cache-2"

     // add and remove
     $hash
      ->addTarget('cache-4')
      ->removeTarget('cache-1');

     // lookup with next-best fallback (for redundant writes)
     $hash->lookupList('object', 2); // ["cache-2", "cache-4"]

     // remove cache-2, expect object to hash to cache-4
     $hash->removeTarget('cache-2');
     $hash->lookup('object'); // "cache-4"



19 : Copyright 2009 Gear6 Inc.
Replication
     • How
           » Repcache
           » Libmemcached


     • Why
           » Two datacenters – master / slave dc’s
           » Keys stored on multiple machines to make them ‘more”
             available




20 : Copyright 2009 Gear6 Inc.
Replication - Repcache Example
     • Downloaded the memcached-(version)-repcached-
       (version).tar.gz source and simply compiled it.
     ./configure --enable-replication
     make
     sudo make install

     Start two instances of memcached on ports 11211 & 11222

     btak@csn07:~/php$ memcached -p 11211 -m 64 -x 127.0.0.1 -v
     replication: connect (peer=127.0.0.1:11212)
     replication: marugoto copying
     replication: close
     replication: listen

     btak@csn07:~/php$ memcached -p 11222 -m 64 -x 127.0.0.1 -v
     replication: connect (peer=127.0.0.1:11212)
     replication: marugoto copying
     Replication: start

21 : Copyright 2009 Gear6 Inc.
Replication – Repcache Example Cont
     Now set and get a value on instance on   Connect to port 11222 and try getting
       port 11211                               this value

     btak@csn07:~$ telnet localhost 11211     btak@csn07:~$ telnet localhost 11222
     Trying 127.0.0.1...                      • Trying 127.0.0.1...
     Connected to localhost.                  • Connected to localhost.
     Escape character is '^]'.                • Escape character is '^]'.
     set hello 0 0 5                          • get hello
     world                                    • VALUE hello 0 5
     STORED                                   • world
     get hello                                • END
     VALUE hello 0 5
     world
     END




22 : Copyright 2009 Gear6 Inc.
Replication – Repcache Example Cont
     Suppose server on 11211 goes down    Let’s see if its replicated on 11211

     On port 11211                        btak@csn07:~$ telnet localhost 11211
     Killed                               Trying 127.0.0.1...
     btak@csn07:~/php$ memcached -11211   Connected to localhost.
        -m 64 -x 127.0.0.1 -v             Escape character is '^]'.
     replication: connect                 get hello
        (peer=127.0.0.1:11222)            VALUE hello 0 5
     replication: marugoto copying        world
     replication: start                   END
                                          get key
     On port 11222
                                          VALUE key 0 5
     <---snip
                                          myval
     replication: close
                                          END
     replication: listen
     replication: accept
     replication: marugoto start
     replication: marugoto 2
     replication: marugoto owari
     <---snip-->

23 : Copyright 2009 Gear6 Inc.
Clustering
     • www.linux-ha.org

     • Provides high availability clustering solution

     • Can enable memcached cluster

     • Combine with consistent hashing




24 : Copyright 2009 Gear6 Inc.
About Gear6
  • First and leading provider
    of Memcached solutions

  • Memcached solution including

          • High density

          • High Availability

          • Advanced memory
            management

          • Enhanced reporting
            capabilities

          • Support for multi-tenancy

          • Disruption free
            software upgrades

          • 100% client compatible


25 : Copyright 2009 Gear6 Inc.
References
     • http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-using-
       deployment.html

     • http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-using-
       hashtypes.html

     • http://jayant7k.blogspot.com/2009/04/memcached-replication.html

     • http://www.lexemetech.com/2007/11/consistent-hashing.html

     • http://www8.org/w8-papers/2a-
       webserver/caching/paper2.htmlhttp://www.last.fm/user/RJ/journal/2007/04/10/rz
       _libketama_-_a_consistent_hashing_algo_for_memcache_clients

     • http://bazaar.launchpad.net/~libmemcached-
       developers/libmemcached/trunk/revision/539




26 : Copyright 2009 Gear6 Inc.
Questions?



                                 Thank you for attending
          “Creating High Availability Services for Your Memcached
                     Environment presented” by Gear6




                                        Bill Takacs
                                           Gear6
                                   salesinfo@gear6.com
                                      +1 650 587 7118

27 : Copyright 2009 Gear6 Inc.

More Related Content

What's hot

What's hot (20)

Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouse
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
 
Hacking WebApps for fun and profit : how to approach a target?
Hacking WebApps for fun and profit : how to approach a target?Hacking WebApps for fun and profit : how to approach a target?
Hacking WebApps for fun and profit : how to approach a target?
 
Supporting Apache HBase : Troubleshooting and Supportability Improvements
Supporting Apache HBase : Troubleshooting and Supportability ImprovementsSupporting Apache HBase : Troubleshooting and Supportability Improvements
Supporting Apache HBase : Troubleshooting and Supportability Improvements
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Apache HBase Performance Tuning
Apache HBase Performance TuningApache HBase Performance Tuning
Apache HBase Performance Tuning
 
Building and running cloud native cassandra
Building and running cloud native cassandraBuilding and running cloud native cassandra
Building and running cloud native cassandra
 
Pentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerPentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A Primer
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practice
 
Replication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTIDReplication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTID
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 
Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to Nginx
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability Solutions
 
Automated master failover
Automated master failoverAutomated master failover
Automated master failover
 
Secure code practices
Secure code practicesSecure code practices
Secure code practices
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
 

Similar to Implementing High Availability Caching with Memcached

Gear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with MemcachedGear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with Memcached
Gear6
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010
Mark Atwood
 
Improving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with MemcachedImproving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with Memcached
Acquia
 

Similar to Implementing High Availability Caching with Memcached (20)

Gear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with MemcachedGear6 Webinar - MySQL Scaling with Memcached
Gear6 Webinar - MySQL Scaling with Memcached
 
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
Gear6 and Scaling Website Performance:  Caching Session and Profile Data with...Gear6 and Scaling Website Performance:  Caching Session and Profile Data with...
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Improving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve InternetImproving Website Performance with Memecached Webinar | Achieve Internet
Improving Website Performance with Memecached Webinar | Achieve Internet
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010
 
Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability Tutorial
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbase
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin Charles
 
OpenSolaris Web Stack MySQL BOF
OpenSolaris Web Stack MySQL BOFOpenSolaris Web Stack MySQL BOF
OpenSolaris Web Stack MySQL BOF
 
MariaDB on Docker
MariaDB on DockerMariaDB on Docker
MariaDB on Docker
 
The New MariaDB Offering: MariaDB 10, MaxScale and More
The New MariaDB Offering: MariaDB 10, MaxScale and MoreThe New MariaDB Offering: MariaDB 10, MaxScale and More
The New MariaDB Offering: MariaDB 10, MaxScale and More
 
Improving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with MemcachedImproving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with Memcached
 
Apache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutApache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling Out
 
(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive(DAT407) Amazon ElastiCache: Deep Dive
(DAT407) Amazon ElastiCache: Deep Dive
 
Oracle RAC and Docker: The Why and How
Oracle RAC and Docker: The Why and HowOracle RAC and Docker: The Why and How
Oracle RAC and Docker: The Why and How
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016
 
Introduction to MariaDB
Introduction to MariaDBIntroduction to MariaDB
Introduction to MariaDB
 
MySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated EnvironmentMySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated Environment
 

More from Gear6

More from Gear6 (6)

Evolution of a Memcached Deployment Webinar 2010 01 13
Evolution of a Memcached Deployment Webinar 2010 01 13Evolution of a Memcached Deployment Webinar 2010 01 13
Evolution of a Memcached Deployment Webinar 2010 01 13
 
Introduction to First Commercial Memcached Service for Cloud
Introduction to First Commercial Memcached Service for CloudIntroduction to First Commercial Memcached Service for Cloud
Introduction to First Commercial Memcached Service for Cloud
 
Cloud Scaling with Memcached
Cloud Scaling with MemcachedCloud Scaling with Memcached
Cloud Scaling with Memcached
 
Why Memcached?
Why Memcached?Why Memcached?
Why Memcached?
 
Memcached and the Rise of the Dynamic Web
Memcached and the Rise of the Dynamic WebMemcached and the Rise of the Dynamic Web
Memcached and the Rise of the Dynamic Web
 
Gear6 Web Cache Overview
Gear6 Web Cache OverviewGear6 Web Cache Overview
Gear6 Web Cache Overview
 

Recently uploaded

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
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Implementing High Availability Caching with Memcached

  • 1. Creating High Availability Services for Your Memcached Environment Presented by: Bill Takacs – Director, Product Management 25 August 2009
  • 2. Agenda • Overview of Memcached • High Availability defined • Why HA Memcached • Options for HA Memcached • Gear6 Solution 2 : Copyright 2009 Gear6 Inc.
  • 3. Memcached “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” Ref: http://www.danga.com/memcached/ • Big hash table • Created by Danga Interactive for Live Journal • Significantly reduced database load • Perfect for web sites with high database load • In use by Facebook, Twitter, MyYearBook, others 3 : Copyright 2009 Gear6 Inc.
  • 4. More on Memcached • Takes advantage of available DRAM • Open source • Distributed under BSD license • Server - Current version is 1.4 » http://www.danga.com/memcached/download.bml • Many Clients » http://code.google.com/p/memcached/wiki/Clients 4 : Copyright 2009 Gear6 Inc.
  • 5. How Does Memcached Work? • Client - Server • Hash Function • Memcached » Two stage » Key / value pair 5 : Copyright 2009 Gear6 Inc.
  • 6. Memcached Server • Slab allocator • Libevent based • Simple Protocol (no xml) • Server has internal hash table • Servers are dumb – they don’t know about each other 6 : Copyright 2009 Gear6 Inc.
  • 7. Memcached Server • Limits » Key size = (250 bytes) » 1MB Limit » 32bit/64bit (maximum size of process) • LRU » Least recently accessed items are cycled out » One LRU exists per “slab class” » LRU “evictions” need not be common • Threads? Yes 7 : Copyright 2009 Gear6 Inc.
  • 8. Memcached Clients • Client hashes key to server list • Serializes the object • Many client libraries • Authentication 8 : Copyright 2009 Gear6 Inc.
  • 9. Commands • Storage commands: » Set / Add / Replace / Append / Prepend / CAS • Retrieval commands: » Get / Gets • Delete / increment / decrement • Stats 9 : Copyright 2009 Gear6 Inc.
  • 10. High Availability • High availability: System design and implementation that ensures a certain absolute degree of operational continuity during a given measurement period. • Organizations » OpenSAF Foundation » SAFourm • HA for Memcache 10 : Copyright 2009 Gear6 Inc.
  • 11. Key Concepts • Clustering • Failover • Replication 11 : Copyright 2009 Gear6 Inc.
  • 12. The case for HA Memcache • What Memcache is NOT: » A persistent data store » A database » Application specific » Clustered » A large object cache • The intent is if its not in cache hit the DB • Great when your site’s traffic is small • Let’s look at the evolution of a site 12 : Copyright 2009 Gear6 Inc.
  • 13. The Beginning Web Servers MySQL Database 13 : Copyright 2009 Gear6 Inc.
  • 14. Web traffic grows Memcached Web Servers Memcached MySQL Memcached Database Dynamic content: Result: Site slows down or worse site unavailable 14 : Copyright 2009 Gear6 Inc.
  • 15. Add Memcached as traffic increases Web Servers MySQL Memcached Database Memcached Increases performance but as the site grows so does Memcached 15 : Copyright 2009 Gear6 Inc.
  • 16. Even more traffic Web Servers MySQL Databases Memcached Memcached Memcache Server(s) Memcached Reliance on memcached for performance 16 : Copyright 2009 Gear6 Inc.
  • 17. Options for HA Memcached Not Many… • DIY • Or - Find a solution that leverages memcached that has high availability features 17 : Copyright 2009 Gear6 Inc.
  • 18. Consistent Hashing • Why? • How does it work? • Where 18 : Copyright 2009 Gear6 Inc.
  • 19. Consistent Hashing - Example • PHP – Flexihash – code.google.com/p/flexihash <?php $hash = new Flexihash(); // bulk add $hash->addTargets(array('cache-1', 'cache-2', 'cache-3')); // simple lookup $hash->lookup('object-a'); // "cache-1" $hash->lookup('object-b'); // "cache-2" // add and remove $hash ->addTarget('cache-4') ->removeTarget('cache-1'); // lookup with next-best fallback (for redundant writes) $hash->lookupList('object', 2); // ["cache-2", "cache-4"] // remove cache-2, expect object to hash to cache-4 $hash->removeTarget('cache-2'); $hash->lookup('object'); // "cache-4" 19 : Copyright 2009 Gear6 Inc.
  • 20. Replication • How » Repcache » Libmemcached • Why » Two datacenters – master / slave dc’s » Keys stored on multiple machines to make them ‘more” available 20 : Copyright 2009 Gear6 Inc.
  • 21. Replication - Repcache Example • Downloaded the memcached-(version)-repcached- (version).tar.gz source and simply compiled it. ./configure --enable-replication make sudo make install Start two instances of memcached on ports 11211 & 11222 btak@csn07:~/php$ memcached -p 11211 -m 64 -x 127.0.0.1 -v replication: connect (peer=127.0.0.1:11212) replication: marugoto copying replication: close replication: listen btak@csn07:~/php$ memcached -p 11222 -m 64 -x 127.0.0.1 -v replication: connect (peer=127.0.0.1:11212) replication: marugoto copying Replication: start 21 : Copyright 2009 Gear6 Inc.
  • 22. Replication – Repcache Example Cont Now set and get a value on instance on Connect to port 11222 and try getting port 11211 this value btak@csn07:~$ telnet localhost 11211 btak@csn07:~$ telnet localhost 11222 Trying 127.0.0.1... • Trying 127.0.0.1... Connected to localhost. • Connected to localhost. Escape character is '^]'. • Escape character is '^]'. set hello 0 0 5 • get hello world • VALUE hello 0 5 STORED • world get hello • END VALUE hello 0 5 world END 22 : Copyright 2009 Gear6 Inc.
  • 23. Replication – Repcache Example Cont Suppose server on 11211 goes down Let’s see if its replicated on 11211 On port 11211 btak@csn07:~$ telnet localhost 11211 Killed Trying 127.0.0.1... btak@csn07:~/php$ memcached -11211 Connected to localhost. -m 64 -x 127.0.0.1 -v Escape character is '^]'. replication: connect get hello (peer=127.0.0.1:11222) VALUE hello 0 5 replication: marugoto copying world replication: start END get key On port 11222 VALUE key 0 5 <---snip myval replication: close END replication: listen replication: accept replication: marugoto start replication: marugoto 2 replication: marugoto owari <---snip--> 23 : Copyright 2009 Gear6 Inc.
  • 24. Clustering • www.linux-ha.org • Provides high availability clustering solution • Can enable memcached cluster • Combine with consistent hashing 24 : Copyright 2009 Gear6 Inc.
  • 25. About Gear6 • First and leading provider of Memcached solutions • Memcached solution including • High density • High Availability • Advanced memory management • Enhanced reporting capabilities • Support for multi-tenancy • Disruption free software upgrades • 100% client compatible 25 : Copyright 2009 Gear6 Inc.
  • 26. References • http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-using- deployment.html • http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-using- hashtypes.html • http://jayant7k.blogspot.com/2009/04/memcached-replication.html • http://www.lexemetech.com/2007/11/consistent-hashing.html • http://www8.org/w8-papers/2a- webserver/caching/paper2.htmlhttp://www.last.fm/user/RJ/journal/2007/04/10/rz _libketama_-_a_consistent_hashing_algo_for_memcache_clients • http://bazaar.launchpad.net/~libmemcached- developers/libmemcached/trunk/revision/539 26 : Copyright 2009 Gear6 Inc.
  • 27. Questions? Thank you for attending “Creating High Availability Services for Your Memcached Environment presented” by Gear6 Bill Takacs Gear6 salesinfo@gear6.com +1 650 587 7118 27 : Copyright 2009 Gear6 Inc.