SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
No-SQL : Memcached
a case study
Saifuddin Kaijar
What is Key-Value Pair Store ?
Key-value database From Wikipedia, the free encyclopedia
A key-value store, or key-value database, is a data storage paradigm designed
for storing, retrieving, and managing associative arrays, a data structure more
commonly known today as a dictionary or hash.
Why not RDBMS/SQL ?
Relational Data - Example Table Structure
Why not RDBMS/SQL ?
Why not RDBMS/SQL ?
Why not RDBMS/SQL ?
Relational databases, due to their referential integrity
property, it’s very difficult for them to offer partition
tolerance and horizontal scaling.
Need to Scale
SQL join is very costly
Why not RDBMS/SQL ?
In addition to scale-out requirement, there was another
handicap in relational databases: Schema-on-write. The
static schema of relational databases is perfect to make
faster known-data-queries.
But Internet data is schema-less and sometimes you need
some kind of flexible schema to manage unknown-data.
If not SQL then What ????
Not only SQL refers to the different types of databases capable of solving
the volume and variety problems that relational databases can’t solve
properly.
NoSQL Data Model
NoSQL Data Model
What is Key-Value Pair Store ?
Key-value database From Wikipedia, the free encyclopedia
A key-value store, or key-value database, is a data storage paradigm designed
for storing, retrieving, and managing associative arrays, a data structure more
commonly known today as a dictionary or hash.
The Basics of Key/Value Caching
A popular solution to this problem is to augment the RDBMS with a Key/Value
(K/V) cache such as memcached.
This optimization offloads most read operations from the database. Thus, reads
are faster because they’re serviced primarily from the cache, and writes
(transactions) are faster because they’re not contending with reads.
The Basics of Key/Value Caching
A popular solution to this problem is to augment the RDBMS with a Key/Value
(K/V) cache such as memcached.
This optimization offloads most read operations from the database. Thus, reads
are faster because they’re serviced primarily from the cache, and writes
(transactions) are faster because they’re not contending with reads.
History of Memcached
Brad Fitzpatrick from Danga Interactive developed
memcached to enhance speed of livejournal.com, which was
then doing 20 million+ dynamic KV’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 > 800 dedicated memcached servers that serves
28 terabytes of memory .
Three W’s
What is Memcached?
Memcached is a high-performance, in-memory distributed memory object caching system, generic
in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
When can we use it?
Anywhere, if you have spare RAM. Mostly used in wiki, social networking and book marking sites.
Why 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.
Multiple Memcached server
Current Memcached Architecture
Memcached has 4 main data structures, including
● A hash table to locate a cache item.
● Least Recently Used (LRU) list to determine cache item
eviction order when the cache is full.
● A cache item data structure for holding the key, data,
flags, and pointers.
● A slab allocator, which is the memory manager for cache
item data structures.
Current Memcached Architecture
Memcached has 4 main data structures, including
● A hash table to locate a cache item.
● Least Recently Used (LRU) list to determine cache item
eviction order when the cache is full.
● A cache item data structure for holding the key, data,
flags, and pointers.
Basic Memcached Data Structure for Data Storing is BLOB :
Header i.e. Access Time, Size of Blob, Reference Count, Expire Time
Key
Payload Data
Current Memcached Architecture
Current Memcached Architecture
Basic memcached Operations
The interface to memcached supports the following methods for storing and retrieving information in the cache, and these are
consistent across all the different APIs, although the language specific mechanics might be different:
● get(key): Retrieves information from the cache.
● store(key, value [, expiry]): Sets the item associated with a key in the cache to the
specified value.
● add(key, value [, expiry]): Adds the key and associated value to the cache, if the
specified key does not already exist.
● replace(key, value [, expiry]): Replaces the item associated with the specified key, only
if the key already exists. The new value is given by the value parameter.
● delete(key [, time]): Deletes the key and its associated item from the cache. If you supply
a time, then adding another item with the specified key is blocked for the specified period.
● incr(key , value): Increments the item associated with the key by the specified value.
● decr(key , value): Decrements the item associated with the key by the specified value.
● flush_all: Invalidates (or expires) all the current items in the cache.
For the three primary commands (GET, STORE, and DELETE), the flow
of memcached is as follows:
1. Request arrives at NIC and is processed by libevent
2. A worker thread
○ Takes connection and data packet
○ Determines the command and data
3. A hash value is created from the key data.
4. The cache lock is acquired to begin hash table and LRU
processing. (Critical Section)
○ (STORE only)
■ Cache item memory is allocated.
■ Data is loaded into the cache item data structure
(flags, key, and value).
○ Hash table is traversed to GET, STORE, or DELETE the
cache item from the hash table.
○ LRU is modified to place move cache item in the front of
the LRU (GET, STORE) or remove it (DELETE).
○ Cache item flags are updated
5. Cache lock is released. (End of Critical Section)
6. Response is constructed.
7. (GET only) Cache lock is asserted.
○ Cache item reference counter is decremented.
○ Cache lock is released.
8. Response is transmitted back to requesting client (i.e. Front-end
Web server).
Memcached Hashing
Memcached Hashing
Memcached Consistent Hashing
Memcached Consistent Hashing
Problems of Memcached
● Cold Cache : Since the new memcached server node is empty at the start, all data requests
need to be serviced by the database servers in the RDBMS layers until that cache node warms up.
● No build-in Security from Memcached : Memcached has no security or authentication.
Please ensure that your server is appropriately firewalled, and that the port(s) used for memcached
servers are not publicly accessible.
● Non Persist : No persistence of data. Everything goes away when you restart it.
● Limited to Host Primary Memory
Scaling and Improving of Memcached
Web Application Data Base
Scaling and Improving of Memcached
Web Application Data Base
Area of Improvement :
● Network stack for efficient request processing:
● Fast and scalable parallel data access:
● New data structures for key-value storage:
Scaling and Improving of Memcached
Web Application Data Base
Area of Improvement :
● Network stack for efficient request processing:
○ Network I/O is one of the most expensive processing steps for
in-memory key-value storage. TCP processing alone may consume
70% of CPU time on a many-core optimized key-value store
○ Direct NIC access
Scaling and Improving of Memcached
Area of Improvement :
● Fast and scalable parallel data access:
○ Concurrent access vs Exclusive access
CPU Core
CPU Core
CPU Core
CPU Core
Shared Data
CPU Core
CPU Core
CPU Core
CPU Core
Concurrent access Exclusive access
Partition 0
Partition 1
Partition 2
Partition 3
Scaling and Improving of Memcached
Area of Improvement :
● New data structures for key-value storage:
○ Improved Hashing Technique
○ Efficient Command Structure
○ Indexing in memcached
○ Improved Changing
○ Efficient memory management Slab Allocator
Memcached Demo
Memcached Server starting :
$ /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
Memcached Strong Key-Value :
char *keys[]= {"alok", "saif", "abhijit"};
char *values[]= {"red", "blue", "green"};
$ ./memcmcache_store
Memcached fetch value for corresponding key :
$ ./memcmcache_fetch 0
References :
● H. Lim, D. Han, D. G. Andersen, and M. Kaminsky, “MICA: A holistic
approach to fast in-memory key-value storage,” in NSDI, 2014.
● “Enhancing the Scalability of Memcached” James T Langston Jr (Intel)'s
picture Submitted by James T Langston Jr (Intel) on August 16, 2012
● Sheng Li, Hyeontaek Lim, Victor W. Lee, Jung Ho Ahn, Anuj Kalia, at. al.
ISCA’15, June 13-17, 2015, Portland, “Architecting to Achieve a Billion
Requests Per Second Throughput on a Single Key-Value Store Server
Platform”
● http://memcached.org/
Thank You

Contenu connexe

Tendances

P C I L O C A L B U S
P C I  L O C A L  B U S P C I  L O C A L  B U S
P C I L O C A L B U S
jainfu2
 
Pci express3-device-architecture-optimizations-idf2009-presentation
Pci express3-device-architecture-optimizations-idf2009-presentationPci express3-device-architecture-optimizations-idf2009-presentation
Pci express3-device-architecture-optimizations-idf2009-presentation
jkcontee
 
Io Architecture
Io ArchitectureIo Architecture
Io Architecture
Aero Plane
 
Micro channel architecture
Micro channel architectureMicro channel architecture
Micro channel architecture
Gichelle Amon
 

Tendances (20)

44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
 
PCI & ISA bus
PCI & ISA busPCI & ISA bus
PCI & ISA bus
 
13. peripheral component interconnect (pci)
13. peripheral component interconnect (pci)13. peripheral component interconnect (pci)
13. peripheral component interconnect (pci)
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
 
Thaker q3 2008
Thaker q3 2008Thaker q3 2008
Thaker q3 2008
 
Isa Dma & Bus Masters
Isa Dma & Bus MastersIsa Dma & Bus Masters
Isa Dma & Bus Masters
 
P C I L O C A L B U S
P C I  L O C A L  B U S P C I  L O C A L  B U S
P C I L O C A L B U S
 
PCI Slot
PCI SlotPCI Slot
PCI Slot
 
Pci express3-device-architecture-optimizations-idf2009-presentation
Pci express3-device-architecture-optimizations-idf2009-presentationPci express3-device-architecture-optimizations-idf2009-presentation
Pci express3-device-architecture-optimizations-idf2009-presentation
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIe
 
Io Architecture
Io ArchitectureIo Architecture
Io Architecture
 
PCI
PCIPCI
PCI
 
Bus Interfacing with Intel Microprocessors Based Systems
Bus Interfacing with Intel Microprocessors Based SystemsBus Interfacing with Intel Microprocessors Based Systems
Bus Interfacing with Intel Microprocessors Based Systems
 
Micro channel architecture
Micro channel architectureMicro channel architecture
Micro channel architecture
 
Pci
PciPci
Pci
 
Isa bus nptel
Isa bus nptelIsa bus nptel
Isa bus nptel
 
Introduction to armv8 aarch64
Introduction to armv8 aarch64Introduction to armv8 aarch64
Introduction to armv8 aarch64
 
Storage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 NotesStorage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 Notes
 
Memory model
Memory modelMemory model
Memory model
 
GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64
 

Similaire à No sql presentation

Mysql wp memcached
Mysql wp memcachedMysql wp memcached
Mysql wp memcached
kbour23
 
IMDB_Scalability
IMDB_ScalabilityIMDB_Scalability
IMDB_Scalability
Israel Gold
 
Project Presentation Final
Project Presentation FinalProject Presentation Final
Project Presentation Final
Dhritiman Halder
 
IMDB_Scalability
IMDB_ScalabilityIMDB_Scalability
IMDB_Scalability
Israel Gold
 
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
Databricks
 
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory ComputingIMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
In-Memory Computing Summit
 

Similaire à No sql presentation (20)

Mysql wp memcached
Mysql wp memcachedMysql wp memcached
Mysql wp memcached
 
Mysql wp memcached
Mysql wp memcachedMysql wp memcached
Mysql wp memcached
 
NoSQL Consepts
NoSQL ConseptsNoSQL Consepts
NoSQL Consepts
 
No sql exploration keyvaluestore
No sql exploration   keyvaluestoreNo sql exploration   keyvaluestore
No sql exploration keyvaluestore
 
Nosql databases
Nosql databasesNosql databases
Nosql databases
 
Introducing Mache
Introducing MacheIntroducing Mache
Introducing Mache
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
 
Big Data_Architecture.pptx
Big Data_Architecture.pptxBig Data_Architecture.pptx
Big Data_Architecture.pptx
 
IMDB_Scalability
IMDB_ScalabilityIMDB_Scalability
IMDB_Scalability
 
Project Presentation Final
Project Presentation FinalProject Presentation Final
Project Presentation Final
 
IMDB_Scalability
IMDB_ScalabilityIMDB_Scalability
IMDB_Scalability
 
NoSQL.pptx
NoSQL.pptxNoSQL.pptx
NoSQL.pptx
 
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
Extending Apache Spark SQL Data Source APIs with Join Push Down with Ioana De...
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached Presentation
 
NoSQL Basics and MongDB
NoSQL Basics and  MongDBNoSQL Basics and  MongDB
NoSQL Basics and MongDB
 
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory ComputingIMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
IMCSummit 2015 - Day 2 General Session - Flash-Extending In-Memory Computing
 
Understanding and building big data Architectures - NoSQL
Understanding and building big data Architectures - NoSQLUnderstanding and building big data Architectures - NoSQL
Understanding and building big data Architectures - NoSQL
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Building a High Performance Analytics Platform
Building a High Performance Analytics PlatformBuilding a High Performance Analytics Platform
Building a High Performance Analytics Platform
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 

Dernier

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

No sql presentation

  • 1. No-SQL : Memcached a case study Saifuddin Kaijar
  • 2. What is Key-Value Pair Store ? Key-value database From Wikipedia, the free encyclopedia A key-value store, or key-value database, is a data storage paradigm designed for storing, retrieving, and managing associative arrays, a data structure more commonly known today as a dictionary or hash.
  • 3. Why not RDBMS/SQL ? Relational Data - Example Table Structure
  • 6. Why not RDBMS/SQL ? Relational databases, due to their referential integrity property, it’s very difficult for them to offer partition tolerance and horizontal scaling. Need to Scale SQL join is very costly
  • 7. Why not RDBMS/SQL ? In addition to scale-out requirement, there was another handicap in relational databases: Schema-on-write. The static schema of relational databases is perfect to make faster known-data-queries. But Internet data is schema-less and sometimes you need some kind of flexible schema to manage unknown-data.
  • 8. If not SQL then What ???? Not only SQL refers to the different types of databases capable of solving the volume and variety problems that relational databases can’t solve properly.
  • 9.
  • 10.
  • 13. What is Key-Value Pair Store ? Key-value database From Wikipedia, the free encyclopedia A key-value store, or key-value database, is a data storage paradigm designed for storing, retrieving, and managing associative arrays, a data structure more commonly known today as a dictionary or hash.
  • 14. The Basics of Key/Value Caching A popular solution to this problem is to augment the RDBMS with a Key/Value (K/V) cache such as memcached. This optimization offloads most read operations from the database. Thus, reads are faster because they’re serviced primarily from the cache, and writes (transactions) are faster because they’re not contending with reads.
  • 15. The Basics of Key/Value Caching A popular solution to this problem is to augment the RDBMS with a Key/Value (K/V) cache such as memcached. This optimization offloads most read operations from the database. Thus, reads are faster because they’re serviced primarily from the cache, and writes (transactions) are faster because they’re not contending with reads.
  • 16. History of Memcached Brad Fitzpatrick from Danga Interactive developed memcached to enhance speed of livejournal.com, which was then doing 20 million+ dynamic KV’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 > 800 dedicated memcached servers that serves 28 terabytes of memory .
  • 17.
  • 18. Three W’s What is Memcached? Memcached is a high-performance, in-memory distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. When can we use it? Anywhere, if you have spare RAM. Mostly used in wiki, social networking and book marking sites. Why 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.
  • 19.
  • 21. Current Memcached Architecture Memcached has 4 main data structures, including ● A hash table to locate a cache item. ● Least Recently Used (LRU) list to determine cache item eviction order when the cache is full. ● A cache item data structure for holding the key, data, flags, and pointers. ● A slab allocator, which is the memory manager for cache item data structures.
  • 22. Current Memcached Architecture Memcached has 4 main data structures, including ● A hash table to locate a cache item. ● Least Recently Used (LRU) list to determine cache item eviction order when the cache is full. ● A cache item data structure for holding the key, data, flags, and pointers. Basic Memcached Data Structure for Data Storing is BLOB : Header i.e. Access Time, Size of Blob, Reference Count, Expire Time Key Payload Data
  • 25. Basic memcached Operations The interface to memcached supports the following methods for storing and retrieving information in the cache, and these are consistent across all the different APIs, although the language specific mechanics might be different: ● get(key): Retrieves information from the cache. ● store(key, value [, expiry]): Sets the item associated with a key in the cache to the specified value. ● add(key, value [, expiry]): Adds the key and associated value to the cache, if the specified key does not already exist. ● replace(key, value [, expiry]): Replaces the item associated with the specified key, only if the key already exists. The new value is given by the value parameter. ● delete(key [, time]): Deletes the key and its associated item from the cache. If you supply a time, then adding another item with the specified key is blocked for the specified period. ● incr(key , value): Increments the item associated with the key by the specified value. ● decr(key , value): Decrements the item associated with the key by the specified value. ● flush_all: Invalidates (or expires) all the current items in the cache.
  • 26. For the three primary commands (GET, STORE, and DELETE), the flow of memcached is as follows: 1. Request arrives at NIC and is processed by libevent 2. A worker thread ○ Takes connection and data packet ○ Determines the command and data 3. A hash value is created from the key data. 4. The cache lock is acquired to begin hash table and LRU processing. (Critical Section) ○ (STORE only) ■ Cache item memory is allocated. ■ Data is loaded into the cache item data structure (flags, key, and value). ○ Hash table is traversed to GET, STORE, or DELETE the cache item from the hash table. ○ LRU is modified to place move cache item in the front of the LRU (GET, STORE) or remove it (DELETE). ○ Cache item flags are updated 5. Cache lock is released. (End of Critical Section) 6. Response is constructed. 7. (GET only) Cache lock is asserted. ○ Cache item reference counter is decremented. ○ Cache lock is released. 8. Response is transmitted back to requesting client (i.e. Front-end Web server).
  • 31. Problems of Memcached ● Cold Cache : Since the new memcached server node is empty at the start, all data requests need to be serviced by the database servers in the RDBMS layers until that cache node warms up. ● No build-in Security from Memcached : Memcached has no security or authentication. Please ensure that your server is appropriately firewalled, and that the port(s) used for memcached servers are not publicly accessible. ● Non Persist : No persistence of data. Everything goes away when you restart it. ● Limited to Host Primary Memory
  • 32. Scaling and Improving of Memcached Web Application Data Base
  • 33. Scaling and Improving of Memcached Web Application Data Base Area of Improvement : ● Network stack for efficient request processing: ● Fast and scalable parallel data access: ● New data structures for key-value storage:
  • 34. Scaling and Improving of Memcached Web Application Data Base Area of Improvement : ● Network stack for efficient request processing: ○ Network I/O is one of the most expensive processing steps for in-memory key-value storage. TCP processing alone may consume 70% of CPU time on a many-core optimized key-value store ○ Direct NIC access
  • 35. Scaling and Improving of Memcached Area of Improvement : ● Fast and scalable parallel data access: ○ Concurrent access vs Exclusive access CPU Core CPU Core CPU Core CPU Core Shared Data CPU Core CPU Core CPU Core CPU Core Concurrent access Exclusive access Partition 0 Partition 1 Partition 2 Partition 3
  • 36. Scaling and Improving of Memcached Area of Improvement : ● New data structures for key-value storage: ○ Improved Hashing Technique ○ Efficient Command Structure ○ Indexing in memcached ○ Improved Changing ○ Efficient memory management Slab Allocator
  • 37.
  • 38. Memcached Demo Memcached Server starting : $ /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 Memcached Strong Key-Value : char *keys[]= {"alok", "saif", "abhijit"}; char *values[]= {"red", "blue", "green"}; $ ./memcmcache_store Memcached fetch value for corresponding key : $ ./memcmcache_fetch 0
  • 39. References : ● H. Lim, D. Han, D. G. Andersen, and M. Kaminsky, “MICA: A holistic approach to fast in-memory key-value storage,” in NSDI, 2014. ● “Enhancing the Scalability of Memcached” James T Langston Jr (Intel)'s picture Submitted by James T Langston Jr (Intel) on August 16, 2012 ● Sheng Li, Hyeontaek Lim, Victor W. Lee, Jung Ho Ahn, Anuj Kalia, at. al. ISCA’15, June 13-17, 2015, Portland, “Architecting to Achieve a Billion Requests Per Second Throughput on a Single Key-Value Store Server Platform” ● http://memcached.org/