flask 四种wsgi方式对比(tornado,Gunicorn,Twisted,Gevent)

本文通过siege工具测试了使用不同WSGI服务器(Tornado、Gunicorn、Twisted、Gevent)运行Flask应用的性能。分别展示了每个服务器的命令行启动方式以及 siege 测试结果,揭示了它们在高并发场景下的表现差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用工具: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
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值