SlideShare uma empresa Scribd logo
1 de 15
MemcacheD
--Abhishek Tomar
Agenda
●
Memcached
●
Features
●
Why use memcached?
●
How Memcached works
●
Basic Layout
●
Memcached Limits
●
Memcahed Server
●
Tips for optimization
●
Exercise
What is MemcacheD?
●
Fast, Multi-Threaded
●
Stores Data in RAM only ( Key | Value )
●
Excellent Read performance
●
Great write performance
●
API available for most language
●
Data distributed multiple servers.
●
Not the replacement of your DB
Features
● Least Recently Used (LRU) Cache:
-- LRU items are ejected if necessary
● Very Low CPU overhead
● Minimal impact of a node failure
● Multi Gets:
-- Parallel Fetches of key|value pairs from multiple
servers in fewer operations than single-gets
● Horizontally Scalable:
-- More Server Creates more Capacity
-- No Single point of failure
Why & When use MemcacheD?
● To reduced the database server load by caching the
data
● Database is getting lot's of 'SELECT' request, (Require
extremely fast read)
● To get maximum "scale out" of minimum hardware
● To store Session data
● Dynamic data that changes infrequently
How MemcacheD work
● Server stores data in HASH table (KEY | VALUE)
pairs.
● Client calculates hash, runs modulo to figure out
which server
● When the server is identified, clients sends its
request
● Server performs a HASH key lookup for actual data
UserRequests
MemCacheD
First Lookup in MemCache.
If Present, Return it.
Database
**Else query the database,
store it in memcache and return it.
**If the data changes, delete it from cache.
Basic Layout
Memcached Limits
● A Single Key cannot be more than 250 bytes.
-- All chars except, whitespace or control chars
● A Single Value can not contain more than 1MB
data
-- arbitrary data
MemcacheD Server
(Installation & Administration)
Installation
● Memcached Server Installation
-- # apt-get install memcached
● Memcached Tools for administration
-- # apt-get install libmemcached-tools
● Memcache PHP client
-- # apt-get install php5-memcache
-- To enable memcache module Restart apache
-- # /etc/init.d/apache2 restart
Configuration Options
● Memory : Default is 64MB
● Simultaneous incoming connections : Default is 1024
● Port number : Default port is 11211
● Type of process - foreground or daemon
● Threads
● TCP / UDP
Storage and Retrieval Commands
➢ 'get' - retrieves KEY|VALUE pairs
➢ 'set' - stores data, possibly overwriting existing data
➢ 'add' - stores data, if NOT exists
➢ 'replace' - stores data, if already exists
➢ 'append' - adds to last byte of existing value
➢ 'prepend' - inverse of append
➢ 'cas' (compare-and-swap) - if data has NOT changed
since we read it last
Administering the MemcacheD
● Connect with telnet
-- telnet localhost 11211
-- 'stats' - returns current statistics
-- We can run 'get KEY' | 'delete KEY'
● Use 'libmemcached-tools'
-- 'memcstat --servers localhost[,host2,host3]' : Reveals
stats of target server(s)
-- stats include : 'bytes', 'limit_maxbytes', 'curr_items', 'get_*',
etc.
Tips for optimization
● By default MemcacheD implements NO AUTH - So
protection is important
● If MemcacheD is published to the NET, use SASL AUTH
● Use a non standard port
● Run MemcacheD in DMZ enviornment
● Run as a non-priviledged user to minimize potential
damage
● Pre warm your cache using scripts
Exercise

Mais conteúdo relacionado

Mais procurados

From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
guestd34230
 
Monitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the WildMonitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the Wild
Tim Vaillancourt
 
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
Tim Vaillancourt
 

Mais procurados (17)

From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
hbaseconasia2017: hbase-2.0.0
hbaseconasia2017: hbase-2.0.0hbaseconasia2017: hbase-2.0.0
hbaseconasia2017: hbase-2.0.0
 
Velocity 2010 - ATS
Velocity 2010 - ATSVelocity 2010 - ATS
Velocity 2010 - ATS
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014
 
Silverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsSilverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applications
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
hbaseconasia2017: Large scale data near-line loading method and architecture
hbaseconasia2017: Large scale data near-line loading method and architecturehbaseconasia2017: Large scale data near-line loading method and architecture
hbaseconasia2017: Large scale data near-line loading method and architecture
 
Optimization_of_Virtual_Machines_for_High_Performance
Optimization_of_Virtual_Machines_for_High_PerformanceOptimization_of_Virtual_Machines_for_High_Performance
Optimization_of_Virtual_Machines_for_High_Performance
 
Rit 2011 ats
Rit 2011 atsRit 2011 ats
Rit 2011 ats
 
Monitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the WildMonitoring MongoDB’s Engines in the Wild
Monitoring MongoDB’s Engines in the Wild
 
Accelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheAccelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket Cache
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the Cloud
 
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
One Tool to Rule Them All- Seamless SQL on MongoDB, MySQL and Redis with Apac...
 
Webinar: StorPool and WHIR - better storage, better business
Webinar: StorPool and WHIR - better storage, better businessWebinar: StorPool and WHIR - better storage, better business
Webinar: StorPool and WHIR - better storage, better business
 
Inside CynosDB: MariaDB optimized for the cloud at Tencent
Inside CynosDB: MariaDB optimized for the cloud at TencentInside CynosDB: MariaDB optimized for the cloud at Tencent
Inside CynosDB: MariaDB optimized for the cloud at Tencent
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
 
hbaseconasia2017: Apache HBase at Netease
hbaseconasia2017: Apache HBase at Neteasehbaseconasia2017: Apache HBase at Netease
hbaseconasia2017: Apache HBase at Netease
 

Destaque

Log.os info
Log.os infoLog.os info

Destaque (9)

Cyber worlds
Cyber worldsCyber worlds
Cyber worlds
 
Log.os info
Log.os infoLog.os info
Log.os info
 
AIDS.gov Mobile Presentation for US Conference on AIDS 2011
AIDS.gov Mobile Presentation for US Conference on AIDS 2011AIDS.gov Mobile Presentation for US Conference on AIDS 2011
AIDS.gov Mobile Presentation for US Conference on AIDS 2011
 
Docker
DockerDocker
Docker
 
Intro to design webcast
Intro to design webcastIntro to design webcast
Intro to design webcast
 
Intro to Docker at the 2016 Evans Developer relations conference
Intro to Docker at the 2016 Evans Developer relations conferenceIntro to Docker at the 2016 Evans Developer relations conference
Intro to Docker at the 2016 Evans Developer relations conference
 
Mobile webseiten deutscher Banken im Test
Mobile webseiten deutscher Banken im TestMobile webseiten deutscher Banken im Test
Mobile webseiten deutscher Banken im Test
 
Informationen über Infrarotkabinen
Informationen über InfrarotkabinenInformationen über Infrarotkabinen
Informationen über Infrarotkabinen
 
Groups 2010.12: Geht die 'beste' Demokratie nur online? (Digital Sustainability)
Groups 2010.12: Geht die 'beste' Demokratie nur online? (Digital Sustainability)Groups 2010.12: Geht die 'beste' Demokratie nur online? (Digital Sustainability)
Groups 2010.12: Geht die 'beste' Demokratie nur online? (Digital Sustainability)
 

Semelhante a Memcache d

Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
 

Semelhante a Memcache d (20)

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
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
 
StripeEu Twistedbytes Presentation
StripeEu Twistedbytes PresentationStripeEu Twistedbytes Presentation
StripeEu Twistedbytes Presentation
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
Lonestar php scalingmagento
Lonestar php scalingmagentoLonestar php scalingmagento
Lonestar php scalingmagento
 
Designing enterprise drupal
Designing enterprise drupalDesigning enterprise drupal
Designing enterprise drupal
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached Presentation
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
How to reduce database load using Memcache
How to reduce database load using MemcacheHow to reduce database load using Memcache
How to reduce database load using Memcache
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 

Memcache d

  • 2. Agenda ● Memcached ● Features ● Why use memcached? ● How Memcached works ● Basic Layout ● Memcached Limits ● Memcahed Server ● Tips for optimization ● Exercise
  • 3. What is MemcacheD? ● Fast, Multi-Threaded ● Stores Data in RAM only ( Key | Value ) ● Excellent Read performance ● Great write performance ● API available for most language ● Data distributed multiple servers. ● Not the replacement of your DB
  • 4. Features ● Least Recently Used (LRU) Cache: -- LRU items are ejected if necessary ● Very Low CPU overhead ● Minimal impact of a node failure ● Multi Gets: -- Parallel Fetches of key|value pairs from multiple servers in fewer operations than single-gets ● Horizontally Scalable: -- More Server Creates more Capacity -- No Single point of failure
  • 5. Why & When use MemcacheD? ● To reduced the database server load by caching the data ● Database is getting lot's of 'SELECT' request, (Require extremely fast read) ● To get maximum "scale out" of minimum hardware ● To store Session data ● Dynamic data that changes infrequently
  • 6. How MemcacheD work ● Server stores data in HASH table (KEY | VALUE) pairs. ● Client calculates hash, runs modulo to figure out which server ● When the server is identified, clients sends its request ● Server performs a HASH key lookup for actual data
  • 7. UserRequests MemCacheD First Lookup in MemCache. If Present, Return it. Database **Else query the database, store it in memcache and return it. **If the data changes, delete it from cache. Basic Layout
  • 8. Memcached Limits ● A Single Key cannot be more than 250 bytes. -- All chars except, whitespace or control chars ● A Single Value can not contain more than 1MB data -- arbitrary data
  • 10. Installation ● Memcached Server Installation -- # apt-get install memcached ● Memcached Tools for administration -- # apt-get install libmemcached-tools ● Memcache PHP client -- # apt-get install php5-memcache -- To enable memcache module Restart apache -- # /etc/init.d/apache2 restart
  • 11. Configuration Options ● Memory : Default is 64MB ● Simultaneous incoming connections : Default is 1024 ● Port number : Default port is 11211 ● Type of process - foreground or daemon ● Threads ● TCP / UDP
  • 12. Storage and Retrieval Commands ➢ 'get' - retrieves KEY|VALUE pairs ➢ 'set' - stores data, possibly overwriting existing data ➢ 'add' - stores data, if NOT exists ➢ 'replace' - stores data, if already exists ➢ 'append' - adds to last byte of existing value ➢ 'prepend' - inverse of append ➢ 'cas' (compare-and-swap) - if data has NOT changed since we read it last
  • 13. Administering the MemcacheD ● Connect with telnet -- telnet localhost 11211 -- 'stats' - returns current statistics -- We can run 'get KEY' | 'delete KEY' ● Use 'libmemcached-tools' -- 'memcstat --servers localhost[,host2,host3]' : Reveals stats of target server(s) -- stats include : 'bytes', 'limit_maxbytes', 'curr_items', 'get_*', etc.
  • 14. Tips for optimization ● By default MemcacheD implements NO AUTH - So protection is important ● If MemcacheD is published to the NET, use SASL AUTH ● Use a non standard port ● Run MemcacheD in DMZ enviornment ● Run as a non-priviledged user to minimize potential damage ● Pre warm your cache using scripts

Notas do Editor

  1. In-Memory DB ( key | Value Pairs) :- All operation are conduct in memory that makes it too fast L1 = 1NS L2 = 4.7NS RAM = 83NS Hard Disk = 13.7MS RAM is 165,000 times faster than disk Key: -> 250-bytes (max) - All chars except: whitespace or control chars Values: -> 1MB (max) of arbitray data
  2. Caching is mostly used for data that is accessed repeatedly, so that instead of calculating/retrieving from the disk repeatedly, which takes time, we can instead directly look it up in the cache, which is much faster.