Tornado开发实践

2,838 views

Published on

Tornado Development In Practice

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,838
On SlideShare
0
From Embeds
0
Number of Embeds
1,054
Actions
Shares
0
Downloads
46
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Tornado开发实践

  1. 1. tornado开发实践 twitter: @bf4x github: @bufferx
  2. 2. 简介 ● written in Python ● non-blocking ● event driven, base on epoll in linux ● lightweight
  3. 3. 由来 ● friendfeed[http://friendfeed.com/] ● 多人在线实时服务 ● facebook
  4. 4. 开源 ● github[https://github.com/facebook/tornado] ● main contributor[https://github.com/bdarnell] ● latest stable version: 3.0.1 ● 3years ● 1000+ commits ● issues, open:, close: 728 ● pull requests, open: 25, close: 780
  5. 5. 应用场景 HTTPSERVER ● Long Polling/COMET服务 ● WebSockets ● 接口服务
  6. 6. 应用场景 Async Client ● 与存储服务的异步IO (Mongo/Redis/Memcached/...) ● 基于HTTP的异步下载(HTTPCLIENT) ● Long Lived Connection ● 移动推送服务
  7. 7. 项目实践 ● 10+关键路径服务 ● 机票/酒店/度假/图片等
  8. 8. 项目实践 ● 接口服务 ● 与多种后端服务交互,如 memcached/mongodb/redis/httpserver
  9. 9. 技术特性 ● 进程级缓存 ● 与后端网络服务的异步交互 ● 协程/装饰器
  10. 10. 环境搭建 ● virtualenv ● supervisord ● nginx
  11. 11. IBE系统 Apache Benchmark(connection=20000) 单进程单实例 数据
  12. 12. 开源 ● github[https://github.com/bufferx/twork] ● 25 commits twork
  13. 13. ● MVC风格 ● 一个Tornado接口服务DEMO ● 技术特性示例 ● 通用库支持(已分拆) twork
  14. 14. Tornado源码 核心 ● IOLoop ● IOStream
  15. 15. Tornado源码 关键点 ● Stack Context ● Coroutine ● Decorator ● tornado.gen
  16. 16. Tornado二次开发 ● 网络IO相关 ● 基于IOLoop ● 基于IOStream
  17. 17. Tornado二次开发 ● asyncmongo[https://github.com/bitly/asyncmongo] ● Motor[http://github.com/mongodb/motor/] ● brukva(redis)[https://github.com/evilkost/brukva] ● memcache[https://github.com/dpnova/tornado- memcache] ● tornado-celery[https://github. com/mher/tornado-celery] ● Spyder[http://retresco.github.com/Spyder/] ● 其它
  18. 18. Tornado二次开发 ● KPNS Base On KMPP
  19. 19. 调优 ● 充分利用多核
  20. 20. 调优 ● python语言级 ○ 列表包含/生成器表达式/协程/闭包等 ○ 使用装饰器 ○ 使用__slots__ ○ 避免使用(.)运算符 ○ ...
  21. 21. 调优 ● C扩展 ○ Python C Extension ○ Swig
  22. 22. 调优 ● pypy ● twice times
  23. 23. 不足 ● GIL的原因, CPython多线程时不能充分利用 多核
  24. 24. 注意 ● 单进程单线程, 切忌阻塞操作
  25. 25. who use ● facebook ● 10gen ● bitly ● quora ● zhihu ● admaster ● sae ● ...
  26. 26. Thanks

×