Bjoern不应该比Gunicorn更快吗?
简单应用程序.py
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/suggest/', methods=['POST'])
def hello():
content = request.get_json()
return jsonify(**content), 200
app_server.py
import bjoern
import os
import signal
from simple_app import app
host = '0.0.0.0'
port = 5000
NUM_WORKERS = 2
worker_pids = []
bjoern.listen(app, host, port)
for _ in xrange(NUM_WORKERS):
pid = os.fork()
if pid > 0:
# in master
worker_pids.append(pid)
elif pid == 0:
# in worker
try:
bjoern.run()
except KeyboardInterrupt:
pass
exit()
try:
for _ in xrange(NUM_WORKERS):
os.wait()
except KeyboardInterrupt:
for pid in worker_pids:
os.kill(pid, signal.SIGINT)
将 Bjoern 服务器运行为:
python app_server.py
将 Gunicorn 运行为:
gunicorn -w 2 --bind 0.0.0.0:5000 simple_app:app --timeout 90
主要数据:
Gunicorn:请求 7.53 毫秒最高 10 秒平均值
Bjoern:请求 100 万 24秒最高 10 秒均值
比约恩::
节点的配置都是ec2实例:(使用一个核心运行app_server,另一个运行tsung)
Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-115-virtual x86_64)
vCPU 数量:2