web 部署专题(四):压力测试(二)压力测试实例 flask 四种wsgi方式对比(tornado,Gunicorn,Twisted,Gevent)

使用工具:siege

代码结构:

hello.py

templates

|--hello.html

hello.py代码:

from flask import Flask, render_template
app = Flask(__name__)
 
@app.route('/')
@app.route('/<name>')
def index(name=None):
    return render_template('hello.html',name=name)
 
if __name__ == '__main__':
    app.run(host='0.0.0.0',port=13579, debug=False)

hello.html代码:

from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello World!</h1>
{% endif %}

flask

命令:siege -c 1000 -r 100 -b http://127.0.0.1:13579/3344

结果:

Transactions:               29511 hits
Availability:               95.08 %
Elapsed time:              254.69 secs
Data transferred:            1.15 MB
Response time:                1.16 secs
Transaction rate:          115.87 trans/sec
Throughput:                0.00 MB/sec
Concurrency:              134.19
Successful transactions:       29511
Failed transactions:            1527
Longest transaction:           88.56
Shortest transaction:            0.00

gunicorn 

命令:gunicorn -w 1 -b 127.0.0.1:13578 hello_gunicorn:app

命令:siege -c 1000 -r 100 -b http://127.0.0.1:13578/3344

结果:

Transactions:               57354 hits
Availability:               96.91 %
Elapsed time:              188.50 secs
Data transferred:            2.24 MB
Response time:                0.41 secs
Transaction rate:          304.27 trans/sec
Throughput:                0.01 MB/sec
Concurrency:              124.78
Successful transactions:       57354
Failed transactions:            1831
Longest transaction:           85.62
Shortest transaction:            0.00

tornado

命令:siege -c 1000 -r 100 -b http://127.0.0.1:13577/3344

结果:

Transactions:              217509 hits
Availability:               99.42 %
Elapsed time:              205.48 secs
Data transferred:            8.50 MB
Response time:                0.34 secs
Transaction rate:         1058.54 trans/sec
Throughput:                0.04 MB/sec
Concurrency:              356.45
Successful transactions:      217509
Failed transactions:            1266
Longest transaction:           89.39
Shortest transaction:            0.03

gevent

命令:siege -c 1000 -r 100 -b http://127.0.0.1:13576/3344

结果:

Transactions:              999952 hits
Availability:              100.00 %
Elapsed time:              509.62 secs
Data transferred:           39.10 MB
Response time:                0.48 secs
Transaction rate:         1962.15 trans/sec
Throughput:                0.08 MB/sec
Concurrency:              935.08
Successful transactions:      999952
Failed transactions:              48
Longest transaction:           63.23
Shortest transaction:            0.02

twisted

命令:twistd -n web --port 13575 --wsgi hello_twised.app

命令:siege -c 1000 -r 100 -b http://127.0.0.1:13575/3344

结果:

Transactions:              155276 hits
Availability:               99.14 %
Elapsed time:              321.25 secs
Data transferred:            6.07 MB
Response time:                0.77 secs
Transaction rate:          483.35 trans/sec
Throughput:                0.02 MB/sec
Concurrency:              371.09
Successful transactions:      155276
Failed transactions:            1340
Longest transaction:           83.32
Shortest transaction:            0.04

————————————————
版权声明:本文为CSDN博主「peter-广」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/marscrazy_90/java/article/details/41943211

原文地址:https://www.cnblogs.com/qiu-hua/p/12681680.html