Tornado 异步非阻塞 实验(3)

siege测试结果

siege 10.9.40.173:8888/officialasyn -c10 -r1 ** SIEGE 3.0.8 ** Preparing 10 concurrent users for battle. The server is now under siege.. done. Transactions: 10 hits Availability: 100.00 % Elapsed time: 1.03 secs Data transferred: 0.00 MB Response time: 0.01 secs Transaction rate: 9.71 trans/sec Throughput: 0.00 MB/sec Concurrency: 0.06 Successful transactions: 10 Failed transactions: 0 Longest transaction: 0.02 Shortest transaction: 0.00

ab压测

Document Path: /officialasyn/ Document Length: 306 bytes Concurrency Level: 10 Time taken for tests: 0.016 seconds Complete requests: 10 Failed requests: 0 Non-2xx responses: 10 Total transferred: 4450 bytes HTML transferred: 3060 bytes Requests per second: 640.78 [#/sec] (mean) Time per request: 15.606 [ms] (mean) Time per request: 1.561 [ms] (mean, across all concurrent requests) Transfer rate: 278.46 [Kbytes/sec] received

可见,使用异步fetch的话每个请求都响应得比较快,平均响应时间短。

个人总结

如果要在tornado中实现非阻塞的mysql查询,不要自己折腾去写yield/coroutine/gen这些异步模块,直接用Tornado-MySQL就好了。还有可以考虑用celery等任务队列。

如果是不需要返回结果的异步操作,通过tornado的IO循环,把可以把耗时的任务放到后台异步计算,请求可以接着做别的计算。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4b9fdbd2c2bd83771e0fdede64667ac4.html