Tornado(二)异步web
来源:互联网 发布:console mysql 编辑:程序博客网 时间:2024/05/17 08:51
异步web请求
测试工具
Siege utility
从同步开始
#coding=utf-8import tornado.httpserverimport tornado.ioloopimport tornado.optionsimport tornado.webimport tornado.httpclientfrom tornado.options import define, optionsdefine("port", default=8000, help="run on the given port", type=int)#接受命令行形式的一些参数class IndexHandler(tornado.web.RequestHandler): def get(self): client = tornado.httpclient.HTTPClient() response = client.fetch("http://www.baidu.com") # 同步的相当于request self.write(response.body)if __name__ == "__main__": tornado.options.parse_command_line() #处理命令行 app = tornado.web.Application(handlers=[(r"/", IndexHandler)]) #实例化application http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
同步测试结果
Transactions: 114 hitsAvailability: 100.00 %Elapsed time: 9.99 secsData transferred: 2.58 MBResponse time: 0.60 secsTransaction rate: 11.41 trans/secThroughput: 0.26 MB/secConcurrency: 6.80Successful transactions: 114Failed transactions: 0Longest transaction: 4.67Shortest transaction: 0.01
基础异步调用
class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): client = tornado.httpclient.AsyncHTTPClient() client.fetch("http://www.baidu.com", callback=self.on_response) def on_response(self, response): self.write(response.body) self.finish()
异步测试结果
Transactions: 771 hitsAvailability: 99.87 %Elapsed time: 9.60 secsData transferred: 17.54 MBResponse time: 0.08 secsTransaction rate: 80.31 trans/secThroughput: 1.83 MB/secConcurrency: 6.60Successful transactions: 771Failed transactions: 1Longest transaction: 0.92Shortest transaction: 0.01
0 0
- Tornado(二)异步web
- Tornado——一个异步web服务器
- 深入理解异步Web服务器 Tornado
- tornado web异步框架 和 nodejs 的异步对比
- Tornado异步
- tornado 异步
- Tornado异步
- tornado异步
- 深入理解Tornado——一个异步web服务器
- 深入理解Tornado——一个异步web服务器
- Python Web框架Tornado的异步处理代码示例
- Celery 的学习笔记--tornado异步开发的好朋友<二>
- Tornado官方文档(二)【概述,异步和非阻塞IO】
- tornado学习笔记(二):如何在tornado中以异步的方式调用同步函数
- Tornado web
- (二)Web框架-龙卷风Tornado之世界上最简单的Tornado示例
- Tornado异步原理分析
- 学习tornado -- 异步
- (15.1.21.1)Camera--Picture Structure
- java知识总结(工作一年半差不多两年了,感觉是时候总结一下java,文章内容为本人观点)
- 蓝桥杯B组C语言-猜数字
- Problem on Group Trip UVALive - 7219
- linux task_struct
- Tornado(二)异步web
- spring-web
- 微信小程序学习(二)
- Android开发:Handler的使用(三)
- (15.1.21.2)Camera--Type
- jdk使用exe文件安装后,path无法正常配置
- 腾讯视频转成mp4
- Linux下三类时间、touch更改时间和find命令的使用
- Linux学习笔记06——进程关系