SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Introduction to Memcached

Mark Atwood <matwood@gear6.com>
What is it?

     •open source
     •high performance
     •distributed
     •memory
     •object
     •cache
: Copyright 2009 Gear6 Inc.
How we got here


     •persistent app service processes
     •local variables
     •filesystem caching
     •database query caching
     •shared memory segment caching
     •apache server fragment caching



                              None of these scale OUT
: Copyright 2009 Gear6 Inc.
Scale out
     • Multiple machines access the same memcache
     • Multiple machines running the memcache

     • Buy more machines, not bigger machines

     • Each memcache node is a hash table
     • Memcache client library does consistent hashing
           » looks at key
           » computes hash
           » picks node




: Copyright 2009 Gear6 Inc.
What about the MySQL query cache?



     • A hack that makes poorly written PHP actually work
     • Heavy write load -> Fail
     • Heavy load -> Fail
     • Increasing CPU count -> Fail
     • Database server memory is precious, better spent on
       innodb buffer pool




: Copyright 2009 Gear6 Inc.
Where Memcached Fits


                                                                    Web Stack                                                       Net
                                                                                                                                 Interface
    Storage                                                                                                                                             Clients

                                                                     PHP, Java, Rails, C,
                                                                                                                                             Internet
                                                         Database




                                                                                                      Apache, Nginx,
                       Storage Interface:




                                                                                            Servers



                                                                                                                       Servers
                                                                       Perl, Python
                                            PostgreSQL
                                              MySQL,




                                                                                                                        Web
                                                                                              App
                                                                                                                                  Proxy
                                                                                                                                              CDN

                                                                                                                                  Load                  client cache
 Storage cache                                                                                                                   Balancer

                                                                          Cache Services
                                                                                            memcached




: Copyright 2009 Gear6 Inc.
Memcached: Technical Background
     • Written in C
     • DHT (Distributed Hash Table)                  Memcached
     • 2 Stage                                       Protocol Handler
           » Clients: hash key  server
           » Server: hash key  value
     • Slab Allocator, fast                               Hash
     • Eviction algorithm: LRU
     • Supported clients
           » Java, PHP, Ruby, Perl, Python, C, etc    Slab Manager
     • Key max size: max 250 bytes
     • Object max size: 1 MiB                         Item Manager
     • BSD like License




: Copyright 2009 Gear6 Inc.
Application Changes
     Application Requirements:
           » Modify calls to subsequent
             application logic or database by use
             of memcached client
           » Send requests to memcached server
           » Check application or db layer next
           » Update memcached

     Cons:
           » Requires coding
           » Generic
     Pros:
           »   Some app frameworks already
           »   Performance gains
           »   Back-end complexity reduction
           »   Generic

                                                    Source: MySQL.com


: Copyright 2009 Gear6 Inc.
When coding, think of places to use it
     • In Perl & Python, when you have a big dictionary /
       hash to keep track of work
     • Or a highly used big lookup table.
     • There are modules to “tie” memcache to your
       language’s dictionary API
     • If you are in C, and are wishing for good dictionary
     • To share state between processes




: Copyright 2009 Gear6 Inc.
Pattern: sessions
     • Keep session state in the memcache
     • Turnkey for PHP and for Django
           » pecl install pecl/memcache
           » Enable memcache session handler support? [yes] : yes


     • Win! Avoid sticky HTTP load balancing
     • Win! Avoid hot session table in database
           » often the #1 performance hotspot for web apps




: Copyright 2009 Gear6 Inc.
Pattern: rate limiting
     • Limit access speed
           »   to   login attempts
           »   to   page accesses
           »   to   API calls
           »   to   expensive operations

     • Key of $prefix.$sourceip.$currtime
     • Value of access count
     • Use ADD method to update
     • Use MGET method to retrieve
     • Use expiration to delete



: Copyright 2009 Gear6 Inc.
Pattern: SQL query cache
     • On every SQL query
     • SQL statement is the key
     • Result set is the value
     • Use expire to delete
     • Beware of inconsistancy, but it may be ok




: Copyright 2009 Gear6 Inc.
MySQL User Defined Functions
     • Access memcached from inside queries
     • And from inside stored procedures
     • Can implement the “check cache, then read from table”
       pattern from inside the SQL query, without having to
       rewrite the app
     • Ships with Drizzle DB




: Copyright 2009 Gear6 Inc.
Other things to keep in memcache
     • HTML fragments
     • Image thumbnails
     • Message headers & bodies
     • Unread message list
     • Unread message counter
     • Contact list
     • Work queues
     • API keys
     • Nonces
     • Gearman staged work
     • Remote data fetched over the web
     • Structured file read cache (Wafflegrid)

: Copyright 2009 Gear6 Inc.
Thank you!




                                  Mark Atwood
                                   Director of
                              Community Development
                              <matwood@gear6.com>

: Copyright 2009 Gear6 Inc.

Weitere ähnliche Inhalte

Was ist angesagt?

Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
Bruce Snyder
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
Bruce Snyder
 
Distributed Caching Essential Lessons (Ts 1402)
Distributed Caching   Essential Lessons (Ts 1402)Distributed Caching   Essential Lessons (Ts 1402)
Distributed Caching Essential Lessons (Ts 1402)
Yury Kaliaha
 
Membase Meetup - Silicon Valley
Membase Meetup - Silicon ValleyMembase Meetup - Silicon Valley
Membase Meetup - Silicon Valley
Membase
 
AWS Summit Berlin 2012 Talk on Web Data Commons
AWS Summit Berlin 2012 Talk on Web Data CommonsAWS Summit Berlin 2012 Talk on Web Data Commons
AWS Summit Berlin 2012 Talk on Web Data Commons
Hannes Mühleisen
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMix
Bruce Snyder
 
Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San Francisco
Membase
 

Was ist angesagt? (20)

Memcached Code Camp 2009
Memcached Code Camp 2009Memcached Code Camp 2009
Memcached Code Camp 2009
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
 
Distributed Caching Essential Lessons (Ts 1402)
Distributed Caching   Essential Lessons (Ts 1402)Distributed Caching   Essential Lessons (Ts 1402)
Distributed Caching Essential Lessons (Ts 1402)
 
Red Hat Open Day JBoss Fuse
Red Hat Open Day JBoss FuseRed Hat Open Day JBoss Fuse
Red Hat Open Day JBoss Fuse
 
Membase Introduction
Membase IntroductionMembase Introduction
Membase Introduction
 
Membase East Coast Meetups
Membase East Coast MeetupsMembase East Coast Meetups
Membase East Coast Meetups
 
Membase Meetup - Silicon Valley
Membase Meetup - Silicon ValleyMembase Meetup - Silicon Valley
Membase Meetup - Silicon Valley
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data grids
 
AWS Summit Berlin 2012 Talk on Web Data Commons
AWS Summit Berlin 2012 Talk on Web Data CommonsAWS Summit Berlin 2012 Talk on Web Data Commons
AWS Summit Berlin 2012 Talk on Web Data Commons
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMix
 
An Elastic Metadata Store for eBay’s Media Platform
An Elastic Metadata Store for eBay’s Media PlatformAn Elastic Metadata Store for eBay’s Media Platform
An Elastic Metadata Store for eBay’s Media Platform
 
Sun Web Server Brief
Sun Web Server BriefSun Web Server Brief
Sun Web Server Brief
 
Caching technology comparison
Caching technology comparisonCaching technology comparison
Caching technology comparison
 
Caching technology comparison
Caching technology comparisonCaching technology comparison
Caching technology comparison
 
Membase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San FranciscoMembase Intro from Membase Meetup San Francisco
Membase Intro from Membase Meetup San Francisco
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQL
 
캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라
 
Caching Strategies
Caching StrategiesCaching Strategies
Caching Strategies
 

Andere mochten auch (8)

Making and Breaking Web Services with Ruby
Making and Breaking Web Services with RubyMaking and Breaking Web Services with Ruby
Making and Breaking Web Services with Ruby
 
Caching, Memcached And Rails
Caching, Memcached And RailsCaching, Memcached And Rails
Caching, Memcached And Rails
 
Memcached
MemcachedMemcached
Memcached
 
Behind the Scenes at LiveJournal: Scaling Storytime
Behind the Scenes at LiveJournal: Scaling StorytimeBehind the Scenes at LiveJournal: Scaling Storytime
Behind the Scenes at LiveJournal: Scaling Storytime
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
Metaprogramming JavaScript
Metaprogramming  JavaScriptMetaprogramming  JavaScript
Metaprogramming JavaScript
 
Caching
CachingCaching
Caching
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 

Ähnlich wie Memcached, presented to LCA2010

HPC Web overview - Mobyle Workshop - September 28, 2012
HPC Web overview - Mobyle Workshop - September 28, 2012HPC Web overview - Mobyle Workshop - September 28, 2012
HPC Web overview - Mobyle Workshop - September 28, 2012
Hervé Ménager
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
harendra_pathak
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecture
drewz lin
 
Facebook的架构
Facebook的架构Facebook的架构
Facebook的架构
yiditushe
 
Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01
jgregory1234
 

Ähnlich wie Memcached, presented to LCA2010 (20)

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...
 
Scalable Resilient Web Services In .Net
Scalable Resilient Web Services In .NetScalable Resilient Web Services In .Net
Scalable Resilient Web Services In .Net
 
Google App Engine At A Glance
Google App Engine At A GlanceGoogle App Engine At A Glance
Google App Engine At A Glance
 
HPC Web overview - Mobyle Workshop - September 28, 2012
HPC Web overview - Mobyle Workshop - September 28, 2012HPC Web overview - Mobyle Workshop - September 28, 2012
HPC Web overview - Mobyle Workshop - September 28, 2012
 
OSDC 2017 - Christos Erotocritou - Apache ignite in-memory data fabric
OSDC 2017 - Christos Erotocritou - Apache ignite in-memory data fabricOSDC 2017 - Christos Erotocritou - Apache ignite in-memory data fabric
OSDC 2017 - Christos Erotocritou - Apache ignite in-memory data fabric
 
Qcon
QconQcon
Qcon
 
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
 
Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joo...
Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joo...Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joo...
Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joo...
 
Gear6 Web Cache Overview
Gear6 Web Cache OverviewGear6 Web Cache Overview
Gear6 Web Cache Overview
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
 
20080528dublinpt1
20080528dublinpt120080528dublinpt1
20080528dublinpt1
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecture
 
Facebook的架构
Facebook的架构Facebook的架构
Facebook的架构
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecture
 
Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01
 
slides (PPT)
slides (PPT)slides (PPT)
slides (PPT)
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
OSMC 2023 | IGNITE: Serving Server-Side WASM with Web Awareness with NGINX Un...
OSMC 2023 | IGNITE: Serving Server-Side WASM with Web Awareness with NGINX Un...OSMC 2023 | IGNITE: Serving Server-Side WASM with Web Awareness with NGINX Un...
OSMC 2023 | IGNITE: Serving Server-Side WASM with Web Awareness with NGINX Un...
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
 
Project Zero JavaOne 2008
Project Zero JavaOne 2008Project Zero JavaOne 2008
Project Zero JavaOne 2008
 

Mehr von Mark Atwood

Telephony with OpenShift Twilio and MongoDB
Telephony with OpenShift Twilio and MongoDBTelephony with OpenShift Twilio and MongoDB
Telephony with OpenShift Twilio and MongoDB
Mark Atwood
 
Openshift + Openstack + Fedora = Awesome
Openshift + Openstack + Fedora = AwesomeOpenshift + Openstack + Fedora = Awesome
Openshift + Openstack + Fedora = Awesome
Mark Atwood
 
OpenShift Origin: Build a PaaS Just Like Red Hats
OpenShift Origin: Build a PaaS Just Like Red HatsOpenShift Origin: Build a PaaS Just Like Red Hats
OpenShift Origin: Build a PaaS Just Like Red Hats
Mark Atwood
 
NoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
NoSQL Part 3, or A Modest Proposal for a Heretical Key ValuestoreNoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
NoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
Mark Atwood
 

Mehr von Mark Atwood (8)

How to get one of those Open Source jobs
How to get one of those Open Source jobsHow to get one of those Open Source jobs
How to get one of those Open Source jobs
 
Why is Open Source so Good: Thirty Years of Lessons Learned
Why is Open Source so Good: Thirty Years of Lessons LearnedWhy is Open Source so Good: Thirty Years of Lessons Learned
Why is Open Source so Good: Thirty Years of Lessons Learned
 
Telephony with OpenShift Twilio and MongoDB
Telephony with OpenShift Twilio and MongoDBTelephony with OpenShift Twilio and MongoDB
Telephony with OpenShift Twilio and MongoDB
 
AMD Fusion12 Developer Summit: Introducing Red Hat OpenShift
AMD Fusion12 Developer Summit: Introducing Red Hat OpenShiftAMD Fusion12 Developer Summit: Introducing Red Hat OpenShift
AMD Fusion12 Developer Summit: Introducing Red Hat OpenShift
 
Openshift + Openstack + Fedora = Awesome
Openshift + Openstack + Fedora = AwesomeOpenshift + Openstack + Fedora = Awesome
Openshift + Openstack + Fedora = Awesome
 
OpenShift Origin: Build a PaaS Just Like Red Hats
OpenShift Origin: Build a PaaS Just Like Red HatsOpenShift Origin: Build a PaaS Just Like Red Hats
OpenShift Origin: Build a PaaS Just Like Red Hats
 
NoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
NoSQL Part 3, or A Modest Proposal for a Heretical Key ValuestoreNoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
NoSQL Part 3, or A Modest Proposal for a Heretical Key Valuestore
 
Eucalyptus: Our Story. Presented at LCA2011
Eucalyptus: Our Story. Presented at LCA2011Eucalyptus: Our Story. Presented at LCA2011
Eucalyptus: Our Story. Presented at LCA2011
 

Kürzlich hochgeladen

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
vu2urc
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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)
 
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
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Memcached, presented to LCA2010

  • 1. Introduction to Memcached Mark Atwood <matwood@gear6.com>
  • 2. What is it? •open source •high performance •distributed •memory •object •cache : Copyright 2009 Gear6 Inc.
  • 3. How we got here •persistent app service processes •local variables •filesystem caching •database query caching •shared memory segment caching •apache server fragment caching None of these scale OUT : Copyright 2009 Gear6 Inc.
  • 4. Scale out • Multiple machines access the same memcache • Multiple machines running the memcache • Buy more machines, not bigger machines • Each memcache node is a hash table • Memcache client library does consistent hashing » looks at key » computes hash » picks node : Copyright 2009 Gear6 Inc.
  • 5. What about the MySQL query cache? • A hack that makes poorly written PHP actually work • Heavy write load -> Fail • Heavy load -> Fail • Increasing CPU count -> Fail • Database server memory is precious, better spent on innodb buffer pool : Copyright 2009 Gear6 Inc.
  • 6. Where Memcached Fits Web Stack Net Interface Storage Clients PHP, Java, Rails, C, Internet Database Apache, Nginx, Storage Interface: Servers Servers Perl, Python PostgreSQL MySQL, Web App Proxy CDN Load client cache Storage cache Balancer Cache Services memcached : Copyright 2009 Gear6 Inc.
  • 7. Memcached: Technical Background • Written in C • DHT (Distributed Hash Table) Memcached • 2 Stage Protocol Handler » Clients: hash key  server » Server: hash key  value • Slab Allocator, fast Hash • Eviction algorithm: LRU • Supported clients » Java, PHP, Ruby, Perl, Python, C, etc Slab Manager • Key max size: max 250 bytes • Object max size: 1 MiB Item Manager • BSD like License : Copyright 2009 Gear6 Inc.
  • 8. Application Changes Application Requirements: » Modify calls to subsequent application logic or database by use of memcached client » Send requests to memcached server » Check application or db layer next » Update memcached Cons: » Requires coding » Generic Pros: » Some app frameworks already » Performance gains » Back-end complexity reduction » Generic Source: MySQL.com : Copyright 2009 Gear6 Inc.
  • 9. When coding, think of places to use it • In Perl & Python, when you have a big dictionary / hash to keep track of work • Or a highly used big lookup table. • There are modules to “tie” memcache to your language’s dictionary API • If you are in C, and are wishing for good dictionary • To share state between processes : Copyright 2009 Gear6 Inc.
  • 10. Pattern: sessions • Keep session state in the memcache • Turnkey for PHP and for Django » pecl install pecl/memcache » Enable memcache session handler support? [yes] : yes • Win! Avoid sticky HTTP load balancing • Win! Avoid hot session table in database » often the #1 performance hotspot for web apps : Copyright 2009 Gear6 Inc.
  • 11. Pattern: rate limiting • Limit access speed » to login attempts » to page accesses » to API calls » to expensive operations • Key of $prefix.$sourceip.$currtime • Value of access count • Use ADD method to update • Use MGET method to retrieve • Use expiration to delete : Copyright 2009 Gear6 Inc.
  • 12. Pattern: SQL query cache • On every SQL query • SQL statement is the key • Result set is the value • Use expire to delete • Beware of inconsistancy, but it may be ok : Copyright 2009 Gear6 Inc.
  • 13. MySQL User Defined Functions • Access memcached from inside queries • And from inside stored procedures • Can implement the “check cache, then read from table” pattern from inside the SQL query, without having to rewrite the app • Ships with Drizzle DB : Copyright 2009 Gear6 Inc.
  • 14. Other things to keep in memcache • HTML fragments • Image thumbnails • Message headers & bodies • Unread message list • Unread message counter • Contact list • Work queues • API keys • Nonces • Gearman staged work • Remote data fetched over the web • Structured file read cache (Wafflegrid) : Copyright 2009 Gear6 Inc.
  • 15. Thank you! Mark Atwood Director of Community Development <matwood@gear6.com> : Copyright 2009 Gear6 Inc.

Hinweis der Redaktion

  1. Support the Scaled Web stack
  2. Web 2.0 driving user &amp; traffic growth Key Apps : Entertainment, Communication, Social Networking Key Drivers : Mobile, Broadband, International, Consumer Mobile applications &amp;#x2013; 3G+ is 22% by 2010 (Mobile goes hi speed) Consumer Internet Traffic 2006&amp;#x2013;2012 This category encompasses any IP traffic that crosses the Internet and is not confined to a single service provider&amp;#x2019;s network. Peer-to-peer (P2P) traffic, still the largest share of Internet traffic today, will decrease as a percentage of overall Internet traffic. Internet video streaming and downloads are beginning to take a larger share of bandwidth, and will grow to nearly 50 percent of all consumer Internet traffic in 2012. Fortunately the web stack has evolved. OSS Technologies such as Varnish ( high-performance HTTP accelerator&amp;#x2026; reverse proxy), gearman (open source message queuing system that makes it easy to do distributed job processing using multiple languages&amp;#x2026; function dispatcher) and hadoop (distributed computing platform) Otherwise there would be some hard decisions These horizontal architectures require a distributed caching system at SCALE (for dynamic data&amp;#x2026; video can be cached at the edge) The alternatives in the earlier part of this decade was to scale up and put more memory in the application and database servers
  3. connections, operations