谈谈缓存
Post on 15-Jul-2015
103 Views
Preview:
TRANSCRIPT
谈谈缓存翁伟
缓存⺫⽬目的
• 不同介质访问速度不同
• 进程内 > 内存 > ⺴⽹网络 > 磁盘
• 优化性能
⻚页⾯面缓存
• 前端缓存
• etag / lastmodified / max-age
• 后端缓存
• memcached
• 甜甜圈缓存 Donut Cache
memcached
请求内缓存
直读 Read Through
memcached的问题• 部署
• 集群节点增减
• 雪崩
• 性能
• ⺴⽹网络
• 内存 slot
• CAS: check and save
• 直读
GroupCache• https://github.com/golang/groupcache
• ⽆无需部署
• 避免雪崩 singleflight
• 性能更好
• ⽆无⺴⽹网络IO
• ⽆无CAS
• Go 1.4 Continuous Stack
直写 Write Though
• 理想情况下,数据库零读:只有写⼊入压⼒力,没有读压⼒力
• 数据预热 + 彻底直写
彻底直写
• 提供什么API给应⽤用端?
• 还能不能写SQL了?
• select * from users where sex = ‘f’ order by createAt limit 10, 10
• rails + java怎么办?
实现参考
• https://github.com/nkallen/cache-money
• https://github.com/Wuvist/pysonic
–Phil Karlton
“There are only two hard things in Computer Science: cache invalidation and naming things.”
• 实现『最终⼀一致性』很容易
• Atomic:分布式 事务 很难
• Paxos
• 系统规划就更难
• 排队论
哪个更快?
请求内缓存真的可以?
链接池
• 连接池也是『缓存』
• 数据库链接
• 应⽤用程序链接
• php FPM / rails unicorn
释放哪些链接? MRU 还是 LRU?
Facebook⼏几个团队搞了两年多~https://code.facebook.com/posts/1499322996995183/solving-the-mystery-of-link-
imbalance-a-metastable-failure-state-at-scale/
top related