Download - About Caching
Purpose of Caching
• Different accessing speed of different medium
• In-Process > Memory > Network > Disk
• Cache for Performance Optimization
Web Page Cache
• Browser Cache
• etag / lastmodified / max-age
• Server Cache
• memcached: Full page/pagelet cache
• Donut Cache: Layout cache
memcached issues• Deployment
• modifying nodes in cluster
• Duplicated call to backend when cache miss on multiple client
• Performance
• Network latency
• Memory slot
• CAS: check and save
• Mainly used for Read-through cache
GroupCache• https://github.com/golang/groupcache
• No separated deployment required
• singleflight builtin: avoid duplicated call to backend
• Better performance
• No network IO
• No CAS
• Go 1.4 Continuous Stack: fix memslot issue
Complete Write-Through
• Available API for application?
• Can support SQL?
• select * from users where sex = ‘f’ order by createAt limit 10, 10
Implementation Examples
• https://github.com/nkallen/cache-money
• https://github.com/Wuvist/pysonic
GroupCache + Write-Through?https://github.com/Wuvist/groupcache/commits/group_delete
–Phil Karlton
“There are only two hard things in Computer Science: cache invalidation and naming things.”
• Easy to implement『eventual consistency』
• Atomic:Distributed transaction is difficult
• Paxos
• System provision is more difficult
• http://en.wikipedia.org/wiki/Queueing_theory
Connection Pool
• Pool is also a kind of “cache”
• Database connection pool
• Application connection pool
• php FPM / rails unicorn
Multiple Facebook teams spent two years
https://code.facebook.com/posts/1499322996995183/solving-the-mystery-of-link-imbalance-a-metastable-failure-state-at-scale/