Bjoern v / s Gunicorn POST请求

时间:2017-01-08 10:30:01

标签: python performance webserver gunicorn bjoern

难道Bjoern不应该比Gunicorn更快吗?

simple_app.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:要求1毫秒24秒最高10秒意味着

Gunicorn :: Gunicorn Request Duration

Gunicorn Stats

比约恩::

Bjoern Request Duration

Bjoern Stats

节点的配置都是ec2实例:(使用一个核心运行app_server,另一个核心运行tsung)

Ubuntu 12.04.5 LTS(GNU / Linux 3.2.0-115-virtual x86_64)

vCPU数量:2

1 个答案:

答案 0 :(得分:6)

测试瓶+ bjoern,它真的很快。 也是瓶子+枪支+ meinheld工人

瓶子比烧瓶快“

瓶子:http://bottlepy.org/docs/dev/

meinheld:https://github.com/mopemope/meinheld

每秒请求数:

bottle-py3 408,379

flask-py3 124,800

info:https www techempower.com/benchmarks/#section=data-r13&hw=ph&test=plaintext