采用了的 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 呢?难道只有在数据库操作这些东西的时候,才会表现出异步的优势?
|      1kslr      2017-10-21 17:09:00 +08:00 谁家的业务是显示 hello world 的? | 
|  |      31314258 OP @kslr 我记得前段时间比较过操作数据库的,sanic 加上连接池,优势才有点明显。也没见 sanic 自己吹的那样吊打。 | 
|  |      4takanasi      2017-10-21 17:13:58 +08:00 currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.insert(0, currentdir + '/../../../') 这段的意义是什么? | 
|  |      5lrh3321      2017-10-21 21:14:58 +08:00 没有耗时超操作,干嘛要搞成异步的,这个场景下使用 sanic 肯定不是最优的。 | 
|  |      6zhengxiaowai      2017-10-21 22:49:12 +08:00 你可以在 bottle 中加上 sleep(1) 和  在 sanic 中加上 async.sleep(1) ,再测试一下 | 
|      7mlyy      2017-10-21 22:57:47 +08:00 via iPad 这只是说明了 hello world 主要性能瓶颈在 cpu 计算,而不是 io 等待。 | 
|      8boyxupers      2017-10-22 00:17:25 +08:00 via iPhone 用 python 考虑啥性能… | 
|  |      91314258 OP @lrh3321  @zhengxiaowai @mlyy 这个 performance 的代码可不是我自己写出来的,是 sainc 官方自己的。 我只是奇怪为什么拿这个代码和别人对比,也展示不出自己的优势啊 https://github.com/channelcat/sanic/tree/master/tests/performance | 
|      10boyxupers      2017-10-22 09:29:38 +08:00 via iPhone @zhengxiaowai gunicorn/gevent worker+bottle 试试? | 
|  |      11guyskk0x0      2017-10-22 10:08:10 +08:00 via Android 有几个疑问: 1. ab 的参数,如果把并发数调大,结果如何? 2. gunicorn 用了 meinheld 这个 worker,它是 c 实现的,性能非常好,但可能有很多坑,网上相关的文章也很少。楼主有在生产环境用过吗? | 
|  |      12rogwan      2017-10-22 12:29:52 +08:00 web 框架的性能差别都没影响,瓶颈都在 sql 读写,用什么语言都影响不大 | 
|      13keysona      2017-10-22 15:28:04 +08:00 @1314258  aiohttp Running 30s test @ http://127.0.0.1:8000 30 threads and 30 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.95ms 1.16ms 15.69ms 64.21% Req/Sec 254.29 39.75 626.00 74.09% 228077 requests in 30.04s, 33.71MB read Requests/sec: 7592.38 Transfer/sec: 1.12MB bottle Running 30s test @ http://127.0.0.1:8000 30 threads and 30 connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.50ms 512.94us 11.59ms 94.98% Req/Sec 402.43 64.64 595.00 71.06% 360870 requests in 30.03s, 60.91MB read Requests/sec: 12017.63 Transfer/sec: 2.03MB sanic Running 30s test @ http://127.0.0.1:8000 30 threads and 30 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.83ms 778.22us 14.05ms 81.87% Req/Sec 558.23 95.23 2.00k 75.12% 500849 requests in 30.10s, 58.75MB read Requests/sec: 16642.26 Transfer/sec: 1.95MB | 
|      14keysona      2017-10-22 15:29:13 +08:00 | 
|      15keysona      2017-10-22 16:03:50 +08:00 <script src="https://gist.github.com/keysona/75bae9c86e006e4dec5faf19d1cdfd5b.js"></script> | 
|      16keysona      2017-10-22 16:05:17 +08:00 我这里的测试, 加了 uvloop 的 aiohttp,比没有加的快 1.5 倍... tornado 的测试惨不忍睹... sanic 全方位吊打??? | 
|  |      171314258 OP | 
|      18keysona      2017-10-22 17:19:02 +08:00 | 
|  |      201314258 OP  1 @keysona 查看 sanic 的代码 633 行和 648 行,即使 log_config 在 run 设置了 False 或者 None 最后他还是用回了 self.log_config。即是 Sanic __init__的时候 的 log_config=LOGGING 好笨啊 | 
|      22chenqh      2017-10-24 13:17:58 +08:00 没有 log 的东西和一条咸鱼有什么区别 |