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
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
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
210
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Contextとはなにか
chiroruxx
1
330
AI時代のUIはどこへ行く?その2!
yusukebe
21
7.3k
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
Claspは野良GASの夢をみるか
takter00
0
200
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
Oxcを導入して開発体験が向上した話
yug1224
4
320
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
200
New "Type" system on PicoRuby
pocke
1
970
JavaDoc 再入門
nagise
1
370
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
5.7k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
The World Runs on Bad Software
bkeepers
PRO
72
12k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
200
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
Deep Space Network (abreviated)
tonyrice
0
210
Practical Orchestrator
shlominoach
191
11k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
300
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