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
200
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
180
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
150
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
150
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
140
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
160
PyCon2014China-Zhuhai-jeff
zoomquiet
0
150
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
180
DevFest2014-Zhuhai-Polymer
zoomquiet
0
480
Other Decks in Programming
See All in Programming
どこまでゆるくて許されるのか
tk3fftk
0
470
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
5.7k
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
140
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.7k
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
160
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.4k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
280
Contextとはなにか
chiroruxx
1
390
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
480
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
170
The Curious Case for Waylosing
cassininazir
1
430
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.5k
4 Signs Your Business is Dying
shpigford
187
22k
Unsuck your backbone
ammeep
672
58k
So, you think you're a good person
axbom
PRO
2
2.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
230
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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