Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bjoern v/s Gunicorn POST requests

Isn't Bjoern supposed to faster that 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)

Running Bjoern server as:

python app_server.py

Running Gunicorn as:

gunicorn -w 2 --bind 0.0.0.0:5000 simple_app:app --timeout 90

Main stats:

Gunicorn: request 7.53 msec highest 10sec mean

Bjoern: request 1mn 24sec highest 10sec mean

Gunicorn:: Gunicorn Request Duration

Gunicorn Stats

Bjoern::

Bjoern Request Duration

Bjoern Stats

Configuration of the nodes both are ec2 instances: (Used one core to run the app_server, another to run tsung)

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

Number of vCPUs : 2

like image 691
vin Avatar asked Jan 08 '17 10:01

vin


1 Answers

Test bottle + bjoern, it's really fast. Also bottle + gunicorn + meinheld worker

Bottle is rather faster than flask

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

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

requests per second:

bottle-py3 408,379

flask-py3 124,800

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

like image 133
Alberto Galera Avatar answered Sep 20 '22 01:09

Alberto Galera