部署项目gunicorn、uwsgi性能,测试对比:优缺点

服务器配置:

Intel Core i5 CPU @ 2.3GHz × 2
内存: 2 G
操作系统: Centos7.6 64 位

1.uwsgi 性能测试

新建共用:test.py,代码如下:

from bottle import Bottle, run

app = Bottle()

@app.route('/hello')
def hello():
    return "Hello World!"

if __name__ == "__main__":
    run(app, host='localhost', port=8000)

执行命令:

uwsgi_python --http-socket=:8000 --workers=2 --wsgi-file hello.py --callable app 2>/dev/null

运行结果:

ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   3.288 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      4550000 bytes
HTML transferred:       600000 bytes
Requests per second:    15206.71 [#/sec] (mean)
Time per request:       6.576 [ms] (mean)
Time per request:       0.066 [ms] (mean, across all concurrent requests)
Transfer rate:          1351.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      2       6
Processing:     1    5   1.3      4      14
Waiting:        1    4   1.7      4      12
Total:          4    7   0.8      6      19
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      7
  75%      7
  80%      7
  90%      7
  95%      7
  98%      8
  99%     11
 100%     19 (longest request)

2.gunicorn 性能测试

执行test.py,运行命令如下:

gunicorn -w 2 test:app

运行结果:

ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        gunicorn/19.3.0
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   8.821 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      8600000 bytes
HTML transferred:       600000 bytes
Requests per second:    5668.37 [#/sec] (mean)
Time per request:       17.642 [ms] (mean)
Time per request:       0.176 [ms] (mean, across all concurrent requests)
Transfer rate:          952.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       7
Processing:     3   18   2.0     17      34
Waiting:        3   17   2.0     17      34
Total:         10   18   2.0     17      36

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     17
  75%     18
  80%     18
  90%     19
  95%     23
  98%     23
  99%     24
 100%     36 (longest request)

性能总结:

方案并发最大响应时间(ms)
1.uwsgi1520619
2.gunicorn566836

总体来看,uwsgi 性能要强于 gunicorn 几倍多~

优缺点对比:

gunicorn 相对简单
uwsgi 相对复杂些,繁琐些。但性能更强悍~

部署方案:

  1. uwsgi +nginx (个人使用推荐)

  2. gunicorn + nginx

扩展:知识

nginx 相对 apache 的优点:

  • 轻量级,同样起web 服务,比apache 占用更少的内存及资源
  • 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能
  • 高度模块化的设计,编写模块相对简单
  • 社区活跃,各种高性能模块出品迅速啊
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值