31. 7. Application Problems
● Caching
– Local Cache
● Use Data structure
– External Cache
● Memcache
● Redis
– Caching algorithm
● LRU
● FIFO
● ….
32. 7. Application Problems
● Data serialize
– Text Protocol
● Json, XML
– Binary
● Thrift, Protobuff …
– Compression
● Snapy, ZIP, GZIP
33. 7. Application Problems
● Local cache
– Create a hash map
● localCache = new HashMap();
– Serialize object need to be cached
● serializedObj = JSON.encode(obj);
– Compress data
● compressedObj = GZIP.compress(serializedObj);
– Put to hash cache
● localCache.put(key, compressedObj);
34. 7. Application Problems
– Get from cache
● compressedObj = localCache.get(key);
– Decompress data
● serializedObj = GZIP.decompress(compressedObj);
– Deserialize
● obj = JSON.decode(serializedObj);
37. 7. Application Problems
● Caching algorithm
– Memory is limit
– What to do when memory is full
– FiFO ( First In First Out)
● First item inserted will be removed first
44. 9.Cross Server Problems
● External Cache server
– Memcached
● Memory only
● Slab memory management
● Use libevent for scalable sockets
● Key/Value only
– Twemcache (twitter memcached)
● Heavy
● https://github.com/twitter/twemcache/wiki/Random-
Eviciton-vs-Slab-Automove
46. 9.Cross Server Problems
● Redis
– Memory and disk
– Simple data structure support
● String, hash, sets, list, sorted sets
– Pub/Sub
– Lua scripts
– Support memcached protocol
– Cluster support
47. 9.Cross Server Problems
● Redis data structures
https://image.slidesharecdn.com/kickingasswithredis-
120618095415-phpapp02/95/kicking-ass-with-redis-3-728.jpg