Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PyCon2012ChinaBj-Zhihu
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Zoom.Quiet
October 20, 2012
Programming
180
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PyCon2012ChinaBj-Zhihu
http://cn.pycon.org/2012/schedulebj
Zoom.Quiet
October 20, 2012
More Decks by Zoom.Quiet
See All by Zoom.Quiet
PyCon2014China-Zhuhai-high performance
zoomquiet
0
190
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
170
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
150
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
140
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
140
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
160
PyCon2014China-Zhuhai-jeff
zoomquiet
0
140
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
170
DevFest2014-Zhuhai-Polymer
zoomquiet
0
480
Other Decks in Programming
See All in Programming
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
New "Type" system on PicoRuby
pocke
1
970
AI 輔助遺留系統現代化的經驗分享
jame2408
1
670
A2UI という光を覗いてみる
satohjohn
1
140
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
140
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
350
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.3k
CSC307 Lecture 17
javiergs
PRO
0
320
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
dRuby over BLE
makicamel
2
380
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
860
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
The Cult of Friendly URLs
andyhume
79
6.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Done Done
chrislema
186
16k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
630
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
850
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
It's Worth the Effort
3n
188
29k
New Earth Scene 8
popppiees
3
2.3k
Transcript
Python 在社会化问答⺴⽹网站 中的应⽤用 杨昆
[email protected]
是什么 社会化问答⺴⽹网络 2010 年 12 月 20 ⽇日上线 2011 年
1 月 26 ⽇日公测 2011 年 9 月 2 ⽇日 iPhone 客户端上线
技术选型
• 快速开发,第三⽅方库丰富 • 社区活跃,⽤用户多 • 语法简单易学,开发⼈人员⼀一周左右就能上⼿手,我们⾃自 ⼰己也很熟悉 Python
• 简单轻量,学习成本低 • ⽀支持异步,天然适合做实时 Comet 应⽤用 • FriendFeed 的成熟案例,Facebook 的社区⽀支持
Tornado
• ⾃自带连接池 • 安全,防⽌止 SQL 注⼊入 • 灵活可扩展性强 SQLAlchemy
技术演进 ⽯石器时代 ⻘青铜时代 蒸汽时代 信息时代 2010/10 - 2011/03 2 machines
4k+ commits 5 developers 2011/4 - 2011/10 5-10 machines 1w+ commits 8 developers 2011/11 - now now - future 15+ machines 4w+ commits 20+ developers ?
• Lean Startup • 低成本 • 快速开发 • 专注核⼼心逻辑,外包周边业务 •
访问量增⻓长带来的问题 • 性能问题 • ⺴⽹网络延迟 ⽯石器时代
• 改进 • 硬件和⺴⽹网络环境改善 • 技术⽅方案 • MySQL master/slave •
HAProxy 做热备 • Tornado 解决⾼高并发问题 ⽯石器时代
• ⾼高性能 • ⾮非阻塞,使⽤用 epoll 或者 kqueue • ⽀支持同时数千个持久连接 •
Async Example Tornado Async Programing class MyHandler(RequestHandler): @asynchronous @gen.engine def get(self): http_client = AsyncHTTPClient() response = yield gen.Task(http_client.fetch, "http://example.com") do_something_with_response(response) self.render("template.html")
• 代码⾏行数和访问量急剧膨胀 • 重构和改进 • 架构 • 程序逻辑 • 存储
• 运维和服务质量 ⻘青铜时代
⻘青铜时代:架构
• 问题 • 急剧增⻓长的业务需求 • 数据库承担⼤大量的计算任务 • Tornado 遇到瓶颈 •
解决⽅方案 • Tornado • Celery • Redis ⻘青铜时代:程序逻辑
• 为什么⽤用 Redis • 简单易⽤用 • 功能强⼤大 • 性能强⼤大 Redis
在知乎的使⽤用
• Redis 作为 Cache • 为什么不⽤用 Memcached? • Redis 作为
MQ • Redis 和 Celery 配合 • Redis 作为存储 • Feed/Notification 中使⽤用 Redis 的 sorted set 结构 • 话题组织结构使⽤用 Redis 的 set 结构 Redis 在知乎的使⽤用
• Redis 数据带来的问题 • 数据量⼤大,单个节点放不下 • 单点访问压⼒力⼤大 • Redis Sharding
• open source @ https://github.com/zhihu/redis-shard • consistent hashing, duck-typing API Redis 在知乎的使⽤用
Redis 在知乎的使⽤用 redis-py: redis-shard: >>> client = redis.Redis() >>> client.set('test',
1) >>> client.zadd('testset', 'first', 1) >>> client.zadd('testset', 'second', 2) >>> client.zrange('testset', 0, -1) >>> client = RedisShardAPI(servers) >>> client.set('test', 1) >>> client.zadd('testset', 'first', 1) >>> client.zadd('testset', 'second', 2) >>> client.zrange('testset', 0, -1)
• Cobbler 统⼀一安装配置操作系统 • Puppet 统⼀一管理服务器 • Nagios/Cacti 监控报警 ⻘青铜时代:运维
• 问题 • 代码量⼤大 • 逻辑复杂,紧耦合 • 调试难,开发难 • 开发周期不⼀一致
蒸汽时代
• 解决⽅方案 • 切分服务 代码量⼤大, 开发周期不⼀一致 • 消息服务:Sink 逻辑复杂,紧耦合 •
⽇日志收集:Kids 调试难 • 虚拟开发环境:Hobox 开发难 蒸汽时代
• 按粒度切分服务 • Application • Service • Library (egg) 蒸汽时代:服务切分粒度
• 特性 • Pub/Sub • Session 蒸汽时代:Sink
• ⽣生产 • 消费 蒸汽时代:Sink connect("sink").publish("activity.{0}".format(data_dict["Action"]), json.dumps(data_dict)) @on("activity.answer_create") def send_notification():
...
• 特性 • 树形拓扑结构 • ⽀支持实时订阅(Redis 协议) • 集中存储 •
记录 • logging handler 蒸汽时代:Kids
蒸汽时代:Kids
• 特性 • 虚拟化开发环境 • ⼀一键安装 蒸汽时代:Hobox
• 展望未来 • ZDB:数据中间层 • CI:持续集成 • ⋯⋯ 信息时代
Q&A We are hiring irate! http://www.zhihu.com/jobs