【问题标题】:Bjoern v/s Gunicorn POST requestsBjoern v/s Gunicorn POST 请求
【发布时间】:2017-01-08 10:30:01
【问题描述】:

比约恩不是应该比 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:请求 100 万 24 秒 最高 10 秒平均值

独角兽::

比约恩::

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

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

vCPU 数量:2

【问题讨论】:

  • 速度主要受网络限制。您的具体设置是什么?
  • 添加了配置。
  • 我运行 bjoern 的方式有问题吗?
  • 您是如何进行基准测试并绘制图表的?
  • 我使用另一个节点通过 Tsung 访问服务器(我们只需要一个简单的 xml 文件即可使其运行)tsung.erlang-projects.org/1/01/about

标签: python performance webserver gunicorn bjoern


【解决方案1】:

测试瓶+bjoern,真的很快。 还有瓶子 + gunicorn + meinheld 工人

瓶子比烧瓶快

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

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

每秒请求数:

bottle-py3 408,379

烧瓶-py3 124,800

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

【讨论】:

  • 可以加链接吗?
  • 对于未来的读者,在声称瓶子比烧瓶好之后。我穿过兔子洞。我发现烧瓶适用于任何复杂的项目。另一方面,Bottle 更适合小型服务。希望这可以帮助。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 1970-01-01
  • 2018-06-08
  • 2015-09-13
相关资源
最近更新 更多