• Save
Memcache d
Upcoming SlideShare
Loading in...5
×
 

Memcache d

on

  • 232 views

 

Statistics

Views

Total Views
232
Views on SlideShare
232
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • In-Memory DB ( key | Value Pairs) :- All operation are conduct in memory that makes it too fast <br /> L1 = 1NS <br /> L2 = 4.7NS <br /> RAM = 83NS <br /> Hard Disk = 13.7MS <br /> RAM is 165,000 times faster than disk <br /> Key: -&gt; 250-bytes (max) - All chars except: whitespace or control chars <br /> Values: -&gt; 1MB (max) of arbitray data <br />
  • 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. <br />

Memcache d Memcache d Presentation Transcript

  • 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