SlideShare a Scribd company logo
Why Memcached?

Presented by:
         Bill Takacs – Director, Product Management


September 2009
Agenda

     • Ri of th dynamic web
       Rise f the d  i    b


     • Memcached


     • The web architecture


     • The evolution of a dynamic site and Memcached


     • Gear6 solution

2 : Copyright 2009 Gear6 Inc.
The Web: What’s Changed?

     • Population

     • Traffic

     • Content and applications




3 : Copyright 2009 Gear6 Inc.
Web Growth: Population

           Forrester: 2 2 billion people online globally by 2013
                      2.2




4 : Copyright 2009 Gear6 Inc.
Web Growth: Traffic

        Cisco: “Annual global IP traffic
                Annual
     will exceed two-thirds of a zettabyte
         (
         (667 exabytes) in four y
                  y )           years”
                   [by 2013]
                     Source: Cisco Visual Networking Index,
                                  9 June 2009




5 : Copyright 2009 Gear6 Inc.
Web Growth: Application & Content



                                       Entertainment
                                     Social networking

 Static                                   Media          Dynamic
                                      Communication
                                Community-generated content




6 : Copyright 2009 Gear6 Inc.
But growth can be
Growth can be painful
                painful
       (VERY)
Clients
                                                                                                         Internet

                                                                                                                            CDN
                   ➜ Industry standard servers replaced proprietary SMP
                   ➜ Shift to dynamic content puts strain on origin sites



                                                                                 Interface
                   ➜ Most sites (over 65%) based on LAMP or JAVA




                                                                                                                                  Balancer
                                                                                                                    Proxy


                                                                                                                                   Load
                                                                                    Net




                                                                                                            Web
                                                                                                            W
                                                                                                           Se
                                                                                                            ervers
                                                                                                         Apac
                                                                                                            che, Nginx,
                                                                                                           Lighttpd
                                                                                                           L
                                                                            Web Stack

                                                                                                            App
                                                                                                            A
                                                                                                           Se
                                                                                                            ervers
Web Architecture




                                                                                                  PHP, Java, Rails, C
                                                                                                                    C,
                                         )




                                                                                                     Per Python
                                                                                                        rl,
                                                                                                         Database
                                                                                                              MySQL,
                                                                                                              M
                                                                                                            Pos
                                                                                                              stgreSQL
                                (




                                                                                                                                             8 : Copyright 2009 Gear6 Inc.
                                                                                                         Stora
                                                                                                         Stora
                                                                                                         Stora
                                                                                                         Stora
                                                                                                             age Interfac
                                                                                                             age Interfac
                                                                                                             age Interfac
                                                                                                             age Interfac
                                                                                                                        ce:
                                                                                                                        ce:
                                                                                                                        ce:
                                                                                                                        ce:
                                                                                                           file, block, FC, SCS
                                                                                                           file, block, FC, SCS
                                                                                                           file, block, FC, SCS
                                                                                                           file, block, FC, SCS
                                                                                                                              SI
                                                                                                                              SI
                                                                                                                              SI
                                                                                                                              SI




                                                                                               Storage
What to do?




9 : Copyright 2009 Gear6 Inc.
Clients
                                                        Internet

                                                                           CDN
                                Interface




                                                                                 Balancer
                                                                   Proxy


                                                                                  Load
                                   Net




                                                           Webb
                                                          Serve
                                                              ers                           Cache Servers
New Caching Architecture




                                                                                                            Memcached
                                                        Apache, N
                                                                Nginx,
                                                           Lighttp
                                                                 pd
                           Web S k
                           W b Stack




                                                           Appp
                                                          Serve
                                                              ers
                                                 PHP, Java, R
                                                            Rails, C,
                                                    Perl, Pyt
                                                            thon
for Scaling Out


                                                        Databa
                                                             ase
                                                             MySQL,
                                                           PostgreS
                                                                  SQL




                                                                                                                        10 : Copyright 2009 Gear6 Inc.
                                                        Storage Interface:
                                                        Storage Interface:
                                                        Storage Interface:
                                                        Storage Interface:
                                                          file, block, FC, SCSI




                                              Storage
Memcached: Pillar of Web 2.0 Architecture




                                 “Everything runs
                                   from memory
                                    in Web 2.0”
                                  Evan Weaver, Twitter, March 2009



11 : Copyright 2009 Gear6 Inc.
The Fix: Memcached

         “A high performance, distributed memory object caching
              g p            ,                    y    j         g
              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 LiveJournal

     • Significantly reduced database load

     • Perfect for web sites with high database load

     • In use by Facebook, Twitter, myYearbook, others

12 : Copyright 2009 Gear6 Inc.
More on Memcached

     • Takes advantage of available DRAM

     • Open source
       Ope sou ce

     • Distributed under BSD license

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

     • M
       Many clients
             li t
           » http://code.google.com/p/memcached/wiki/Clients


13 : Copyright 2009 Gear6 Inc.
Why Memcached with MySQL?

     • Scale-out of dynamic web sites
                     y

     • Page loads

     • Efficient resource utilization

     • Support for dozens
       to hundreds of nodes

     • Open source




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

                                 • Client - Server

                                 • H h Function
                                   Hash F  ti

                                 • Memcached
                                   » Two stage




15 : 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




16 : 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”
                                  slab class
           » LRU “evictions” need not
             be common
     • Threads? Yes



17 : Copyright 2009 Gear6 Inc.
Memcached Clients

     • Client hashes key to server list

     • Serializes t e object
       Se a es the

     • Many client libraries
          y

     • Authentication




18 : Copyright 2009 Gear6 Inc.
What about…..

     • Redundancy

     • Failover




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

     • How does it work?




20 : Copyright 2009 Gear6 Inc.
Commands

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


     • Retrieval commands:
           » Get / Gets


     • Delete / increment /
       decrement

     • Stats


21 : Copyright 2009 Gear6 Inc.
Memcached UDFs for MySQL


     • Suite of functions that
       work with Memcached
       and MySQL

     • Leverage power of
       SQL Engine

     • Combine tasks
                                  mySQL
     • Open source
                                 application
                                  pp

22 : Copyright 2009 Gear6 Inc.
Putting it all together

                        Client 1
                        Client-1      Client 2
                                      Client-2            Client 3
                                                          Client-3




                                                      C
                           Server X    Server Y           Server Z

                                      Key = value
                                        y
                                      Foo = seattle
23 : Copyright 2009 Gear6 Inc.
Evolution of a Dynamic Site #1
     A day in the life of a growing web service


    Event: Site has growth in
   number of users, sessions,                          Action: Replicate database
  page views and apps, causing                       (and/or add more app servers)
   excessive read load on DB



                                                           App Server       App Server       App Server
   App Server           App Server   App Server   App Server       App Server    App Server



                        write

                        read                                   write            …    write
                                                               read                  read
                     MySQL                                MySQL                     MySQL




24 : Copyright 2009 Gear6 Inc.
Evolution of a Dynamic Site #2
     A day in the life of a growing web service


  Event: Individual caches on the                                Action: Add memcached server
        app/db servers are                                        on servers with underutilized
  overwhelmed from chaotic, non-                                 memory resources… results in
   deterministic content access                                   even fewer reads to database



                                                                            memcached           memcached          memcached
           App Server            App Server      App Server                App Server          App Server         App Server
                                                               memcached           memcached          memcached
                                                              App Server          App Server        App Server
App Server         App Server         App Server




             write
               it                  …     write
                                           it                              write
                                                                             it                  …      write
                                                                                                          it
             read                        read                              read                         read
          MySQL                        MySQL                           MySQL                          MySQL




25 : Copyright 2009 Gear6 Inc.
Evolution of a Dynamic Site #3
     A day in the life of a growing web service


     Event: Memcached needs
    more memory resources than                                         Action: Move Memcached
     what are available on other                                      servers to dedicated servers
          (shared) servers


              memcached           memcached          memcached
             App Server          App Server         App Server             App Server             App Server      App Server
 memcached           memcached          memcached
App Server          App Server        App Server                 App Server          App Server        App Server

                                                                    memcached         memcached         …         memcached




             write                 …      write                               write                 …     write
             read                         read                                read                        read
          MySQL                         MySQL                             MySQL                         MySQL




26 : Copyright 2009 Gear6 Inc.
What Memcached is NOT:

                                 A persistent data store


                                 A database


                                 Application-specific


                                 A large object cache


                                 Fault-tolerant or highly available

27 : Copyright 2009 Gear6 Inc.
Memcached: Best Practices

                                 • Use with MySQL :-)
                                             y Q    )

                                 • Use on 64-bit servers

                                 • Cache “expensive
                                   operations”

                                 • Cache bi-directionally
                                   (
                                   (read/write)
                                              )

                                 • Design to withstand
                                   failures gracefully

                                 • Use consistent hashing

28 : Copyright 2009 Gear6 Inc.
Memcached: Best Practices (cont’d)

     • Careful with numbers of connections
           » Peak
           » Transitions


     • Evictions
           » Segment Memcached data into separate pools


     • O ti i sizing: instances and pools
       Optimize i i   i t         d    l

     • Instrumentation



29 : Copyright 2009 Gear6 Inc.
Memcache Use Cases

          Site Type                  Repeatable Use

          Social networking          Profile caching

          Content aggregation        HTML/page caching

          Ad targeting               Cookie/profile tracking

          Gaming and entertainment   Session caching

          Location-based services    DB query scaling

          Relationship
          R l ti   hi                Session caching
                                     S   i      hi

          E-commerce                 Session and HTML caching

30 : Copyright 2009 Gear6 Inc.
Use Case Example:
     Session Management

                                              • 4m+ daily visitors

                           Web Servers        • 15k hits/sec
                                              • 6k updates/sec
                   Application S
                               Servers with   • Tens of thousands of
                     Memcached Clients          concurrent connections

                       Memcached Servers
                                              • S
                                                Session tracked and ads
                                                     i   t   k d d d
                                                are placed in accordance
                                                to session
                           MySQL Servers




31 : Copyright 2009 Gear6 Inc.
Useful Memcached Tools

                                  p
                       advanced reporter
                       Track hot keys and clients in Memcached

                       wireshark
                       Dissect and analyze Memcached network traffic

                       brutis
                       Size and test changes to memcache clusters

                       statsproxy
                       View buffered Memcached stats in your browser

                       cacti
                       Graph and analyze Memcached statistics


32 : Copyright 2009 Gear6 Inc.
Statsproxy + Cacti Templates




                                    To use the cacti
                                    templates for
                                    memcached with
                                    statsproxy, you
                                    either need to
                                    modify the
                                    templates to use
                                    port 8080 or
                                    change the
                                    statsproxy config to
                                    use port 11211




33 : 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
                biliti

          • Support for multi-tenancy

          • Disruption free
            software upgrades

          • 100% c e t co pat b e
             00% client compatible


34 : Copyright 2009 Gear6 Inc.
Questions?

                             Thank you for attending our webinar
                                     “Why Memcached”


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



                                 and please visit our web site at:
                                 www.gear6.com
35 : Copyright 2009 Gear6 Inc.
References
     •   Danga.com
     •   Highscalability.com
     •   Dev.gear6.com
     •   Groups.google.com/group/memcached
     •   Code.google.com/p/memcached
     •   Twitter.com/gearsix
     •   Cacti.net
     •   Wireshark.org
     •   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_l
         ibketama_-_a_consistent_hashing_algo_for_memcache_clients
     •   http://bazaar.launchpad.net/~libmemcached-
         http://bazaar launchpad net/~libmemcached
         developers/libmemcached/trunk/revision/539
36 : Copyright 2009 Gear6 Inc.

More Related Content

Viewers also liked (6)

PDF
Memcached: What is it and what does it do? (PHP Version)
Brian Moon
 
PPTX
Load Balancing from the Cloud - Layer 7 Aware Solution
Imperva Incapsula
 
KEY
Memcached: What is it and what does it do?
Brian Moon
 
DOC
L7-L7 Services in a Cloud Datacenter
Vikas Deolaliker
 
PPTX
SIMULATION AND PERFORMANCE ANALYSIS OF A LARGE SCALED INTERNET APPLICATION ...
ankit_saluja
 
KEY
Continuous Deployment
Brian Moon
 
Memcached: What is it and what does it do? (PHP Version)
Brian Moon
 
Load Balancing from the Cloud - Layer 7 Aware Solution
Imperva Incapsula
 
Memcached: What is it and what does it do?
Brian Moon
 
L7-L7 Services in a Cloud Datacenter
Vikas Deolaliker
 
SIMULATION AND PERFORMANCE ANALYSIS OF A LARGE SCALED INTERNET APPLICATION ...
ankit_saluja
 
Continuous Deployment
Brian Moon
 

Similar to Why Memcached? (20)

PDF
Evolution of a Memcached Deployment Webinar 2010 01 13
Gear6
 
PDF
Cloud Scaling with Memcached
Gear6
 
KEY
Cloud Foundry Bootcamp
Joshua Long
 
ZIP
Memcached, presented to LCA2010
Mark Atwood
 
PPTX
Obiee 11 g
prudhviraj_cse
 
PDF
Spring into the Cloud - JDC2012 Cairo, Egypt
Chris Richardson
 
PDF
Eva flex java_1_slides
Michael Chaize
 
PDF
Introduction to First Commercial Memcached Service for Cloud
Gear6
 
ODP
Chisimba - introduction to practical demo
Derek Keats
 
PDF
Layer 7: Securing Web 2.0 - What You Need to Know
CA API Management
 
PDF
Jax2010 adobe lcds
Michael Chaize
 
PDF
Web 2.0 toolset overview
Tom Raftery
 
PDF
Find me if you can – smart fuzzing and discovery! shreeraj shah
owaspindia
 
PPT
FIND ME IF YOU CAN – SMART FUZZING AND DISCOVERY
Shreeraj Shah
 
PDF
Hacking Ajax & Web Services - Next Generation Web Attacks on the Rise
Shreeraj Shah
 
KEY
Gaelyk - Paris GGUG 2011 - Guillaume Laforge
Guillaume Laforge
 
PPT
Introduction to VoiceXml and Voice Web Architecture
Paul Nguyen
 
PDF
Hosting as a Framework
ciconf
 
PDF
Gaelyk - Groovy Grails eXchange 2010 - Guillaume Laforge
Guillaume Laforge
 
PDF
Architecting for Change: QCONNYC 2012
Kellan
 
Evolution of a Memcached Deployment Webinar 2010 01 13
Gear6
 
Cloud Scaling with Memcached
Gear6
 
Cloud Foundry Bootcamp
Joshua Long
 
Memcached, presented to LCA2010
Mark Atwood
 
Obiee 11 g
prudhviraj_cse
 
Spring into the Cloud - JDC2012 Cairo, Egypt
Chris Richardson
 
Eva flex java_1_slides
Michael Chaize
 
Introduction to First Commercial Memcached Service for Cloud
Gear6
 
Chisimba - introduction to practical demo
Derek Keats
 
Layer 7: Securing Web 2.0 - What You Need to Know
CA API Management
 
Jax2010 adobe lcds
Michael Chaize
 
Web 2.0 toolset overview
Tom Raftery
 
Find me if you can – smart fuzzing and discovery! shreeraj shah
owaspindia
 
FIND ME IF YOU CAN – SMART FUZZING AND DISCOVERY
Shreeraj Shah
 
Hacking Ajax & Web Services - Next Generation Web Attacks on the Rise
Shreeraj Shah
 
Gaelyk - Paris GGUG 2011 - Guillaume Laforge
Guillaume Laforge
 
Introduction to VoiceXml and Voice Web Architecture
Paul Nguyen
 
Hosting as a Framework
ciconf
 
Gaelyk - Groovy Grails eXchange 2010 - Guillaume Laforge
Guillaume Laforge
 
Architecting for Change: QCONNYC 2012
Kellan
 
Ad

Recently uploaded (20)

PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Python basic programing language for automation
DanialHabibi2
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
July Patch Tuesday
Ivanti
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Python basic programing language for automation
DanialHabibi2
 
Ad

Why Memcached?

  • 1. Why Memcached? Presented by: Bill Takacs – Director, Product Management September 2009
  • 2. Agenda • Ri of th dynamic web Rise f the d i b • Memcached • The web architecture • The evolution of a dynamic site and Memcached • Gear6 solution 2 : Copyright 2009 Gear6 Inc.
  • 3. The Web: What’s Changed? • Population • Traffic • Content and applications 3 : Copyright 2009 Gear6 Inc.
  • 4. Web Growth: Population Forrester: 2 2 billion people online globally by 2013 2.2 4 : Copyright 2009 Gear6 Inc.
  • 5. Web Growth: Traffic Cisco: “Annual global IP traffic Annual will exceed two-thirds of a zettabyte ( (667 exabytes) in four y y ) years” [by 2013] Source: Cisco Visual Networking Index, 9 June 2009 5 : Copyright 2009 Gear6 Inc.
  • 6. Web Growth: Application & Content Entertainment Social networking Static Media Dynamic Communication Community-generated content 6 : Copyright 2009 Gear6 Inc.
  • 7. But growth can be Growth can be painful painful (VERY)
  • 8. Clients Internet CDN ➜ Industry standard servers replaced proprietary SMP ➜ Shift to dynamic content puts strain on origin sites Interface ➜ Most sites (over 65%) based on LAMP or JAVA Balancer Proxy Load Net Web W Se ervers Apac che, Nginx, Lighttpd L Web Stack App A Se ervers Web Architecture PHP, Java, Rails, C C, ) Per Python rl, Database MySQL, M Pos stgreSQL ( 8 : Copyright 2009 Gear6 Inc. Stora Stora Stora Stora age Interfac age Interfac age Interfac age Interfac ce: ce: ce: ce: file, block, FC, SCS file, block, FC, SCS file, block, FC, SCS file, block, FC, SCS SI SI SI SI Storage
  • 9. What to do? 9 : Copyright 2009 Gear6 Inc.
  • 10. Clients Internet CDN Interface Balancer Proxy Load Net Webb Serve ers Cache Servers New Caching Architecture Memcached Apache, N Nginx, Lighttp pd Web S k W b Stack Appp Serve ers PHP, Java, R Rails, C, Perl, Pyt thon for Scaling Out Databa ase MySQL, PostgreS SQL 10 : Copyright 2009 Gear6 Inc. Storage Interface: Storage Interface: Storage Interface: Storage Interface: file, block, FC, SCSI Storage
  • 11. Memcached: Pillar of Web 2.0 Architecture “Everything runs from memory in Web 2.0” Evan Weaver, Twitter, March 2009 11 : Copyright 2009 Gear6 Inc.
  • 12. The Fix: Memcached “A high performance, distributed memory object caching g p , y j g 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 LiveJournal • Significantly reduced database load • Perfect for web sites with high database load • In use by Facebook, Twitter, myYearbook, others 12 : Copyright 2009 Gear6 Inc.
  • 13. More on Memcached • Takes advantage of available DRAM • Open source Ope sou ce • Distributed under BSD license • Server - Current version is 1.2.8 » http://www.danga.com/memcached/download.bml • M Many clients li t » http://code.google.com/p/memcached/wiki/Clients 13 : Copyright 2009 Gear6 Inc.
  • 14. Why Memcached with MySQL? • Scale-out of dynamic web sites y • Page loads • Efficient resource utilization • Support for dozens to hundreds of nodes • Open source 14 : Copyright 2009 Gear6 Inc.
  • 15. How Does Memcached Work? • Client - Server • H h Function Hash F ti • Memcached » Two stage 15 : Copyright 2009 Gear6 Inc.
  • 16. 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 16 : Copyright 2009 Gear6 Inc.
  • 17. 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” slab class » LRU “evictions” need not be common • Threads? Yes 17 : Copyright 2009 Gear6 Inc.
  • 18. Memcached Clients • Client hashes key to server list • Serializes t e object Se a es the • Many client libraries y • Authentication 18 : Copyright 2009 Gear6 Inc.
  • 19. What about….. • Redundancy • Failover 19 : Copyright 2009 Gear6 Inc.
  • 20. Consistent Hashing • Why? • How does it work? 20 : Copyright 2009 Gear6 Inc.
  • 21. Commands • Storage commands: » Set / Add / Replace / Append / Prepend / CAS • Retrieval commands: » Get / Gets • Delete / increment / decrement • Stats 21 : Copyright 2009 Gear6 Inc.
  • 22. Memcached UDFs for MySQL • Suite of functions that work with Memcached and MySQL • Leverage power of SQL Engine • Combine tasks mySQL • Open source application pp 22 : Copyright 2009 Gear6 Inc.
  • 23. Putting it all together Client 1 Client-1 Client 2 Client-2 Client 3 Client-3 C Server X Server Y Server Z Key = value y Foo = seattle 23 : Copyright 2009 Gear6 Inc.
  • 24. Evolution of a Dynamic Site #1 A day in the life of a growing web service Event: Site has growth in number of users, sessions, Action: Replicate database page views and apps, causing (and/or add more app servers) excessive read load on DB App Server App Server App Server App Server App Server App Server App Server App Server App Server write read write … write read read MySQL MySQL MySQL 24 : Copyright 2009 Gear6 Inc.
  • 25. Evolution of a Dynamic Site #2 A day in the life of a growing web service Event: Individual caches on the Action: Add memcached server app/db servers are on servers with underutilized overwhelmed from chaotic, non- memory resources… results in deterministic content access even fewer reads to database memcached memcached memcached App Server App Server App Server App Server App Server App Server memcached memcached memcached App Server App Server App Server App Server App Server App Server write it … write it write it … write it read read read read MySQL MySQL MySQL MySQL 25 : Copyright 2009 Gear6 Inc.
  • 26. Evolution of a Dynamic Site #3 A day in the life of a growing web service Event: Memcached needs more memory resources than Action: Move Memcached what are available on other servers to dedicated servers (shared) servers memcached memcached memcached App Server App Server App Server App Server App Server App Server memcached memcached memcached App Server App Server App Server App Server App Server App Server memcached memcached … memcached write … write write … write read read read read MySQL MySQL MySQL MySQL 26 : Copyright 2009 Gear6 Inc.
  • 27. What Memcached is NOT: A persistent data store A database Application-specific A large object cache Fault-tolerant or highly available 27 : Copyright 2009 Gear6 Inc.
  • 28. Memcached: Best Practices • Use with MySQL :-) y Q ) • Use on 64-bit servers • Cache “expensive operations” • Cache bi-directionally ( (read/write) ) • Design to withstand failures gracefully • Use consistent hashing 28 : Copyright 2009 Gear6 Inc.
  • 29. Memcached: Best Practices (cont’d) • Careful with numbers of connections » Peak » Transitions • Evictions » Segment Memcached data into separate pools • O ti i sizing: instances and pools Optimize i i i t d l • Instrumentation 29 : Copyright 2009 Gear6 Inc.
  • 30. Memcache Use Cases Site Type Repeatable Use Social networking Profile caching Content aggregation HTML/page caching Ad targeting Cookie/profile tracking Gaming and entertainment Session caching Location-based services DB query scaling Relationship R l ti hi Session caching S i hi E-commerce Session and HTML caching 30 : Copyright 2009 Gear6 Inc.
  • 31. Use Case Example: Session Management • 4m+ daily visitors Web Servers • 15k hits/sec • 6k updates/sec Application S Servers with • Tens of thousands of Memcached Clients concurrent connections Memcached Servers • S Session tracked and ads i t k d d d are placed in accordance to session MySQL Servers 31 : Copyright 2009 Gear6 Inc.
  • 32. Useful Memcached Tools p advanced reporter Track hot keys and clients in Memcached wireshark Dissect and analyze Memcached network traffic brutis Size and test changes to memcache clusters statsproxy View buffered Memcached stats in your browser cacti Graph and analyze Memcached statistics 32 : Copyright 2009 Gear6 Inc.
  • 33. Statsproxy + Cacti Templates To use the cacti templates for memcached with statsproxy, you either need to modify the templates to use port 8080 or change the statsproxy config to use port 11211 33 : Copyright 2009 Gear6 Inc.
  • 34. About Gear6 • First and leading provider of Memcached solutions • Memcached solution including • High density • High availability • Advanced memory management • Enhanced reporting capabilities biliti • Support for multi-tenancy • Disruption free software upgrades • 100% c e t co pat b e 00% client compatible 34 : Copyright 2009 Gear6 Inc.
  • 35. Questions? Thank you for attending our webinar “Why Memcached” Bill Takacs Gear6 [email protected] +1 650 587 7118 and please visit our web site at: www.gear6.com 35 : Copyright 2009 Gear6 Inc.
  • 36. References • Danga.com • Highscalability.com • Dev.gear6.com • Groups.google.com/group/memcached • Code.google.com/p/memcached • Twitter.com/gearsix • Cacti.net • Wireshark.org • 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_l ibketama_-_a_consistent_hashing_algo_for_memcache_clients • http://bazaar.launchpad.net/~libmemcached- http://bazaar launchpad net/~libmemcached developers/libmemcached/trunk/revision/539 36 : Copyright 2009 Gear6 Inc.