• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Memcache
 

Memcache

on

  • 24,646 views

Memcache is 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.

Memcache is 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.

Statistics

Views

Total Views
24,646
Views on SlideShare
17,858
Embed Views
6,788

Actions

Likes
9
Downloads
260
Comments
2

23 Embeds 6,788

http://abhinavsingh.com 6064
http://sentidoweb.com 564
http://heeha.wordpress.com 33
http://www.linkedin.com 28
http://www.slideshare.net 23
http://trantrietvn.blogspot.com 19
http://webcache.googleusercontent.com 16
http://translate.googleusercontent.com 11
http://trantrietvn.blogspot.com.br 5
http://es.paperblog.com 5
https://www.linkedin.com 3
http://74.125.77.132 2
http://trantrietvn.blogspot.tw 2
http://74.125.153.132 2
http://74.125.39.132 2
http://trantrietvn.blogspot.in 2
http://trantrietvn.blogspot.ru 1
http://209.85.129.132 1
http://74.125.45.132 1
http://72.14.203.132 1
http://192.168.10.3 1
http://209.85.135.132 1
http://feeds.feedburner.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hi, just a question about the problem in slide 10, how do you resolve it ?

    In case cached data is out of sync due to replication lag, how to prevent it ? Can we use dirty bit ?
    Are you sure you want to
    Your message goes here
    Processing…
  • Database caching reduces the data redundancy as opposed to object caching as higher level objects are composed of result set of join on multiple tables. Check out CSQL for database caching.

    http://www.csqldb.com
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Memcache Memcache Presentation Transcript

    • Scaling with Memcached http://danga.com/memcached By Abhinav Singh
    • Who all are using it?
    • History of Memcached
      • Brad Fitzpatrick from Danga Interactive developed memcached to enhance speed of livejournal.com , which was then doing 20 million+ dynamic PV’s per day.
      • Memcached reduced the database load to almost nothing, yielding faster page load time and better resource utilization.
      • Facebook is the biggest user of memcached after live journal. They have > 100 dedicated memcached servers.
    • Three W’s
      • W hat is Memcached?
      • Memcached is 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.
      • W hen can we use it?
      • Anywhere, if you have spare RAM
      • Mostly used in wiki, social networking and book marking sites.
      • W hy should we use it?
      • If you have a high-traffic site that is dynamically generated with a high database load that contains mostly read threads then memcached can help lighten the load on your database.
    • Pseudo Implementation PHP DB API Database 1 st time Query Checks cache and if not found extracts from database Cache the serialized resultset in memory 2Gb RAM reserved for caching the resultset http://localhost
    • Pseudo Implementation PHP DB API Database 2 nd time Query Checks cache, resultset already found. Un-serialize and return the resultset 2Gb RAM reserved for caching the resultset http://localhost
    • Pseudo Code
      • $listofphotos = $mdb->getPhotos();
      • $query = “SELECT * from photos where …..”;
      • $key = sha1($query)
      • If ($key FOUND IN memcache) {
      • $value = get($key);
      • $resultset = unserialize($value);
      • return $resultset;
      • }
      • else {
      • $resultset = mysql_query($query);
      • set($key,serialize($resultset),$TTL);
      • return $resultset;
      • }
      • PS: Do not use SQL_FOUND_ROWS in your $query while using memcache
    • Miscellaneous
      • The story of memcache
      • MySQL Query Cache v/s APC v/s Memcache. Why memcache?
      • Deciding your key intelligently (User:md5($query)) or (Messages:sha1($query)).
      • A bit on how to apply versioning in keys.
      • Is memcache secure? No, then what precautions do I take?
      • Reduce load on your database by not updating it for trivial information like timestamp, last changed date etc.
    • Facebook – How do they do?
      • Me: Hey how do you use memcache at facebook?
      • My friend - “A bit of background on our caching model: when a user modifies a data object our infrastructure will write the new value in to a database and delete the old value from memcache (if it was present). The next time a user requests that data object we pull the result from the database and write it to memcache. Subsequent requests will pull the data from memcache until it expires out of the cache or is deleted by another update. “
      • Me: But does this work fine with datacenters spread around different countries?
    • Cross Datacenter Story
      • My Friend from Facebook: Consider this example:
      • 1. I update my first name from “ Abhinav " to " Monkey "
      • 2. We write " Monkey " in to the master database in California and delete my first name from memcache in California and Virginia
      • 3. Someone goes to my profile in Virginia
      • 4. We don't find my first name in memcache so we read from the Virginia slave database and get “ Abhinav " because of replication lag
      • 5. We update Virginia memcache with my first name as “ Abhinav "
      • 6. Replication catches up and we update the slave database with my first name as “ Monkey ”
      • 7. Someone else goes to my profile in Virginia
      • 8. We find my first name in memcache and returns “ Abhinav ”
      • 9. Hence my first name will be shown as “Abhinav” in Virginia and “Monkey” in California. Confusing?
    • Storing and Managing Collections
      • keyArray = GET array of keys from cache IF keyArray NOT NULL   lstItems = MULTI GET keyArray   FOR EACH item IN lstItems      IF item IS NULL         SET item in cache      END IF   END FOR ELSE   lstItems = list of items from persistent data store   FOR EACH item IN lstItems      ADD key for item INTO keyArray      STORE item in cache   END FOR   STORE keyArray in cache END IF RETURN lstItems
    • Why not use memcache?
      • You have objects larger than 1MB.
      • You have keys larger than 250 chars.
      • You're running in an un-secure environment.
      • You want persistence. Or, a database.
      • Questions?
      • Thank You