tornado 异步模型学习和压测总结
来源:互联网 发布:梦里花落知多少抄袭 编辑:程序博客网 时间:2024/05/14 07:38
压测工具、文档、代码请参考 https://github.com/robertzhai/python/tree/master/tornado-basic
1.异步下载天气信息,@tornado.web.asynchonous装饰器
#rate_async.py
class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): client = tornado.httpclient.AsyncHTTPClient() client.fetch("http://www.weather.com.cn/data/sk/101010100.html" , callback=self.on_response) def on_response(self, response): body = json.loads(response.body) print body result_count = len(body['weatherinfo']) self.write(body['weatherinfo']['city']) self.finish()
2.异步下载天气信息,tornado.gen模块
class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @tornado.gen.engine def get(self): client = tornado.httpclient.AsyncHTTPClient() response = yield tornado.gen.Task(client.fetch, "http://www.weather.com.cn/data/sk/101010100.html" ) body = json.loads(response.body) print body result_count = len(body['weatherinfo']) self.write(body['weatherinfo']['city']) self.finish()
3. sync 下载天气
class IndexHandler(tornado.web.RequestHandler): def get(self): client = tornado.httpclient.HTTPClient() response = client.fetch("http://www.weather.com.cn/data/sk/101010100.html" ) body = json.loads(response.body) print body result_count = len(body['weatherinfo']) self.write(body['weatherinfo']['city']) self.finish()
4.压测对比
压测命令:siege http://localhost:8000/ -c50 -t10s
压测结果:async 性能最高
sync
Transactions: 274 hits
Availability: 100.00 %
Elapsed time: 9.94 secs
Data transferred: 0.00 MB
Response time: 1.13 secs
Transaction rate: 27.57 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 31.19
Successful transactions: 274
Failed transactions: 0
Longest transaction: 1.69
Shortest transaction: 0.05
async
Transactions: 857 hits
Availability: 100.00 %
Elapsed time: 9.74 secs
Data transferred: 0.00 MB
Response time: 0.07 secs
Transaction rate: 87.99 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 5.78
Successful transactions: 857
Failed transactions: 0
Longest transaction: 1.23
Shortest transaction: 0.02
gen
Transactions: 780 hits
Availability: 100.00 %
Elapsed time: 9.59 secs
Data transferred: 0.00 MB
Response time: 0.07 secs
Transaction rate: 81.33 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 5.79
Successful transactions: 780
Failed transactions: 0
Longest transaction: 1.17
Shortest transaction: 0.01
- tornado 异步模型学习和压测总结
- 学习tornado -- 异步
- 学习tornado:异步
- Tornado异步学习
- 学习tornado:异步
- gevent和tornado异步
- tornado同步和异步GET
- tornado学习总结
- tornado学习笔记总结
- Tornado异步
- tornado 异步
- Tornado异步
- tornado异步
- epoll的io异步模型与tornado的关系
- tornado web异步框架 和 nodejs 的异步对比
- libco和tornado、协程和异步的一些理解
- Celery 的学习笔记--tornado异步开发的好朋友<一>
- Celery 的学习笔记--tornado异步开发的好朋友<二>
- SLAM and autonomous navigation with ROS + kinect + arduino + android
- 第3章配置日期和时间
- Python 和 Lua 学习比较 二
- vs错误解决办法
- linux中/etc/passwd文件和/etc/shadow文件与/etc/group的解析
- tornado 异步模型学习和压测总结
- 三种算法求解一个数组的子数组最大和
- Unity3D之将UI的点击事件渗透下去
- 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件
- MP4Box Merge MP4 Files
- java 时间处理
- Oracle什么时候需要commit?
- 在UITableViewCell中获取它的父视图
- 强烈推荐android studio用的几个插件