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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Zoom.Quiet
October 20, 2012
Programming
190
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
150
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
170
PyCon2014China-Zhuhai-jeff
zoomquiet
0
160
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
180
DevFest2014-Zhuhai-Polymer
zoomquiet
0
480
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
9
4.8k
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
640
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
霧の中の代数的エフェクト
funnyycat
1
460
Google Apps Script で Ruby を動かす
kawahara
0
130
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
390
FDEが実現するAI駆動経営の現在地
gonta
2
260
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
Claude Team Plan導入・ガイド
tk3fftk
0
250
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
650
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Mind Mapping
helmedeiros
PRO
1
300
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Claude Code のすすめ
schroneko
67
230k
Bash Introduction
62gerente
615
220k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
350
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
360
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
420
Building Applications with DynamoDB
mza
96
7.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
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