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
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
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
470
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
140
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
VibeCodingからAgenticWorkflowへ
starfish719
0
200
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
210
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.8k
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
230
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
650
AIエージェントで 変わるAndroid開発環境
takahirom
2
770
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
その節約、円になってますか?
isamumumu
1
680
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
520
Speed Design
sergeychernyshev
33
2k
Documentation Writing (for coders)
carmenintech
77
5.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
350
Product Roadmaps are Hard
iamctodd
55
12k
GraphQLとの向き合い方2022年版
quramy
50
15k
How STYLIGHT went responsive
nonsquared
100
6.2k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
200
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