2010-04 新浪杨卫华:构建可扩展的微博架构(QCon北京2010)
2020-03-01 149浏览
- 1.构建可扩展微博架构 Tim Yang 新浪微博 技术架构师
- 2.从博客到微博
- 3.博客 • 功能 –发表 –浏览 –留言 • Content Manager System
- 4.博客 • 技术 , LAMP –MySQL master/slave –Memcached –PHP –CDN
- 5.微博 • 微博,产品 –Real-time –关注关系 –信息聚合
- 6.信息聚合
- 7.信息聚合 • 微博两种信息聚合设计模式 –Push( 推 ) –Pull( 拉 )
- 8.Push • 把微博看做邮件 –Inbox:收到的微博 –Outbox:已发表微博 • 发表:存到所有粉丝 inbox( 重 ) • 查看:直接访问 Inbox( 轻 )
- 9.Push(Figure) User A UpdateAction Followers of User A = 1, 2, 3 Inbox (Append to 1’s home timeline) Inbox (Append to 2’s home timeline) Inbox (Append to 3’s home timeline)
- 10.Push • 优点:实现简单,首选 • 缺点:分发量
- 11.Pull • 发表:存到自己 outbox( 轻 ) • 查看:所有关注对象 Inbox( 重 )
- 12.Pull User I Get home_timeline User I’s Following List = A, B, C Outbox (statuses sent by A) Outbox (Statuses sent by B) Outbox (Statuses sent by C)
- 13.Pull • 优点:节约存储 • 缺点:计算量大
- 14.• 微博是一个消息分发系统 • 可采取推或拉的方式实现
- 15.架构挑战:峰值 - 如除夕、春节
- 16.请求量 • 如果发表量 5,000 万 / 天 • 平均: 578 条 / 秒 • 设计系统容量: 2,000?
- 17.IO 瓶颈 • 峰值: 5,000 – 10,000? • 100,000?
- 18.后果 • Latency • DB read timeout • 前端 timeout (503 error) • 解决方案?
- 19.异步设计 • 不同步等待 • 将消息存入消息队列 (Message Queue) • 轻量级的发表
- 20.MQ products • Kestrel by twitter • RabbitMQ, an Erlang Queue Server • Memcacheq –在新浪微博项目大规模使用
- 21.Memcacheq • 基于 Berkeley db, 稳定可 靠 • Memcached protocol, 丰 富的 client library • 容易监控 (stats queue) • 只有 2 个命令: get/set
- 22.避免单点故障 核心服务,需避免单独故障 方法 1. 使用多个 Memcacheq 池 2. Get 操作 : 轮询所有服务器 3. Set 操作 : 随机选择一个 无需其他复杂“架构”设计
- 23.MQ 方式通用的优点 • Offline work • 应用请求量不均衡 • 解耦 • 异步通讯 • 原则
- 24.使用 MQ 原则 计算开销大于消息分发开 销
- 25.架构挑战:实时性
- 26.越重要的事件,越希望实时性
- 27.The value of the tweet decreases exponentially with timehttp://t.sina.com.cn/pub/star#a_tyJohn Kalucki, Twitter
- 28.解决思路 Cache 中心化 Ram is the new the disk
- 29.• Local Cache • Memcached • Database buffer/cache
- 30.• LAMP 中, cache= 可选层 • Cache 中心化后新的问题
- 31.容量问题 • TB 级 • 思路:压缩 –QuickLZ –LZO –不用 gzip
- 32.单点问题 • 单点故障 , SIGSEGV • 如何应对 –1. Consistent hash –2. Read-through cache
- 33.Consistent hash • 原理 • 优点 –震荡最小
- 34.Read-through cache
- 35.Read-through and Writethrough • Products or projects – MySQL memcached UDF – Cache money for Ruby on Rails • Or wrap a proxy for the db driver, in any language
- 36.Evictions 问题 •Evections:cache 数据被踢 • 性能的噩梦 • Latency 产生的源头之一
- 37.如何避免 evictions • 规划 cache 容量 • 将永久数据与临时数据分开 • 不使用随机字符作为 key
- 38.Multiget 问题 When memcached servers are CPU bound, adding more memcached servers doesn't help serve more requests. - Jeff Rothschild, Vice President of Technology at Facebook
- 39.Cache 挑战: multiget hole Multiget Application Max RPS of application < (A and B and C) Multiget Multiget Multiget Multiget (keys…) Memcached (MaxRPS:'>RPS: