python - Bjoern v/s Gunicorn POST 请求

标签 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

应用服务器.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 秒平均值

unicorn :: 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-虚拟 x86_64)

vCPU 数量:2

最佳答案

试水瓶+bjoern,真快。 还有 bottle + gunicorn + meinheld worker

瓶子比 flask 快

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

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

每秒请求数:

bottle-py3 408,379

flask -py3 124,800

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

关于python - Bjoern v/s Gunicorn POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41531707/

相关文章:

python - 在 Python 文档中嵌入图像

java - java中HashMap.containsKey()的时间复杂度是多少?

mysql - 使用三向 JOIN 优化查询

apache - 如何在apache2服务器上部署j2ee应用

android - 如何在组织内部部署 Android 应用程序?

php - 离线更新数据库

python - 将此列表拆分为更小列表的最佳方法?

python - Python 重载装饰器

c - 该乘法算法的时间复杂度是多少?

php - 运行PHP代码而无需等待Python返回值