性能测试: flask WSGI vs 异步 ASGI vs tornodo vs Golang Gin
做一个基本的性能基准测试。测试脚本使用是apach benchmark
测试命令:
ab -kc 1000 -n 4000 http://127.0.0.1:5000/
代码最精简:
flask wsgi:
得到的结果:

ASGI的代码:
运行命令:
uvicorn --host 0.0.0.0 simple_asgi:app
得到的结果:

python的tornado

Goland的gin

通过requests per second 每秒的请求数:
flask : 1000
uvicorn: 2000
tornoda:3000
go gin:4000
所以综合测试结果,flask的性能最烂,go gin的性能最好。差了4倍。
转载请注明出处:
http://www.30daydo.com/article/44336
测试命令:
ab -kc 1000 -n 4000 http://127.0.0.1:5000/
代码最精简:
flask wsgi:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(host='0.0.0.0')
得到的结果:

ASGI的代码:
async def app(scope, receive, send):
await send({
'type': 'http.response.start',
'status': 200,
'headers': [
[b'content-type', b'text/html']
]
})
await send({
'type': 'http.response.body',
'body': b'Hello This is server running',
'more_body': False
})
运行命令:
uvicorn --host 0.0.0.0 simple_asgi:app
得到的结果:

python的tornado
from tornado import ioloop
from tornado import web
class Homepage(web.RequestHandler):
def get(self):
print('get method')
self.write("This is tornado server")
if __name__ == '__main__':
app = web.Application([
("/",Homepage),
])
app.listen(8888)
ioloop.IOLoop.current().start()

Goland的gin
package main
import "github.com/gin-gonic/gin"
// 测试专用
func main() {
r := gin.Default()
r.GET("/index", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "Working"})
})
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "Working"})
})
r.Run()
}

通过requests per second 每秒的请求数:
flask : 1000
uvicorn: 2000
tornoda:3000
go gin:4000
所以综合测试结果,flask的性能最烂,go gin的性能最好。差了4倍。
转载请注明出处:
http://www.30daydo.com/article/44336