采用了的 https://github.com/channelcat/sanic/tree/master/tests/performance 里面的代码. 我就测试了 bottle 和 sanic. bottle 的按照他自己代码
# Run with: gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker -b :8000 simple_server:app
import bottle
from bottle import route, run
import ujson
@route('/')
def index():
return ujson.dumps({'test': True})
app = bottle.default_app()
sanic 的代码如下
import sys
import os
import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.insert(0, currentdir + '/../../../')
from sanic import Sanic
from sanic.response import json
app = Sanic("test")
@app.route("/")
async def test(request):
return json({"test": True})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=sys.argv[1])
ab 都是 ab -n 10000 -c 10 http://192.168.2.110/
结果如下 bottle
HTML transferred: 130000 bytes
Requests per second: 1677.17 [#/sec] (mean)
Time per request: 5.962 [ms] (mean)
Time per request: 0.596 [ms] (mean, across all concurrent requests)
Transfer rate: 281.71 [Kbytes/sec] received
sanic 如下
HTML transferred: 130000 bytes
Requests per second: 526.89 [#/sec] (mean)
Time per request: 18.979 [ms] (mean)
Time per request: 1.898 [ms] (mean, across all concurrent requests)
Transfer rate: 53.00 [Kbytes/sec] received
为什么呢?说好牛逼的 uvloop 和 httptools 呢?难道只有在数据库操作这些东西的时候,才会表现出异步的优势?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.