ElasticCache
Use Case
Dori Waldman - Big Data Lead
AT A
GLANCE
1.2M
TRANSACTIONS/S
8T
RAW DATA /d
NEW YORK
LONDON
SAN
FRANCISCO
TEL AVIV
BEIJING
500-1000
SERVERS
2007
FOUNDED
100EMPLOYEES
800M
UNIQUE USERS
InnerActive in numbers
OUR
MISSION
Ad-Request
RTB
Non RtB
Im
pressions
/ Clicks
1
3
2
High level architecture: fully scale & elastic
Main
DB Stack
Aggregations
Configuration
Analytic - Cube
Analytic
KV -
Cache
SSOT Q
MemCached
Memcached

Simple in-memory Key-Value store ~ HashMap

No persistence (redis is also in memory but use disk for persistence)

No replication

No complex objects (List/Map...) , just strings,Int,byte


LRU eviction policy

Fast

preferable when caching relatively small and static data (html code)

Scale (default 20 nodes in AWS)

Simple
Memcached
Vs.
Redis
Problem:
3 month ago we faced production issue , lots of eviction although there is enough
memory in the cluster, we tried to increase cluster size , change machines , add
memory , play with slab size …
(We are using 16 nodes (r3.xlarge), verison 1.4.33)
Solution: ...
Production
Issue
The Memcached API is very simple, straightforward. But at a certain point, you need implementation knowledge to make sure things are behaving as expected.The Memcached API is very simple, straightforward. But at a certain point, you need implementation knowledge to make sure things are behaving as expected.The Memcached API is very simple, straightforward. But at a certain point, you need implementation knowledge to make sure things are behaving as expected.
Memcached API is very simple, But at a certain point, you need implementation
knowledge to make sure things are behaving as expected.
How it
works
Grow factor of 1.25 : round(104*1.25)=136 ...
P1 - Waste of resources:
If you have objects that are all
720,000 bytes long, they have to fit
in class 42 -- which means a
guaranteed internal wastage of
~30% (remain 1048576-72000)
There is no way to use this memory!
The chunks in each slab have the
same size so there cannot be 2
different sized chunks inside the
same page.
How it
works
P2 – different input sizes/Eviction
Slab 1 might have 800 pages and slab 3 might have 200 pages.
Everything is good, all memory is used , as long as we keep getting another small item “slab class 1”
the LRU eviction of that slab class will handle it,
we might evict item from slab1 although slab3 has older items – but its not that critical like
Once we get medium item, slab 2 has no pages to use, more accurate it has default of one page,
Meaning slab2 eviction will not behave as expected (pages from slab class 1/3 cant re-assign
to class 2)
Memcache will initially create 1 page per slab-class and the rest of the pages will be free.
There can be multiple pages for each slab-class, but as soon as a page is assigned a slab-class
(and thus, split up in chunks), it cannot be changed to another slab-class.
Production
Issue
What we saw :
lets say we have 10G available memory
Our input data should fit to one slab class only (4k size)
Total memory in use is 4M , still we see eviction
Monitoring
use the “stats slabs” command to see where memcached has allocated its memory.
If you watch the various get/set statistics on each slab, you can get an idea on which slabs are hot
Auto Discovery - application does not need to manually connect to individual cache
nodes, instead, your application connects to one Memcached node and retrieves the list
of nodes. From that list your application is aware of the rest of the nodes in the cluster
and can connect to any of them. You do not need to hard code the individual cache node
endpoints in your application. → we are not using it
Consist hashing :
Regular hash: $server_id = hashfunc($key) % $servercount;
Without CH in case we add/remove node , the keys are not relevant , we need to restart
the cluster, with this feature we can look for the key in the neighbor node → we are not
using it
Features
http://balodeamit.blogspot.co.il/2013/10/how-memcached-works.html
https://www.quora.com/How-should-I-configure-memcached-to-efficiently-store-objects-if-I-know-they-will-all-be-at-or-close-to-a-maxim
um-size
http://work.tinou.com/2011/04/memcached-for-dummies.html
Useful
Links
http://www.mikeperham.com/2009/06/22/slabs-pages-chunks-and-memcached/
http://www.adayinthelifeof.nl/2011/02/06/memcache-internals/
THANK YOUDori.waldman@inner-active.com
https://www.linkedin.com/in/doriwaldman/
https://www.slideshare.net/doriwaldman

Memcached