Siege压力测试工具的安装及使用+python flask的四种wsgi方式对比
文章目录
- 一、前言:
- 如果要支持https
- 二、安装使用:
- 文件备份:
- 1、mac安装:
- 2、linux 安装:【centos 服务器】
- 通用Linux安装:
- 3、window安装:
- 4、测试百度:
- 参数:
- 测试百度:
- 5、查看配置文件位置:
- 1)、siege -C
- 2)、找到后缀:siege.conf
- 三、flask 四种wsgi方式对比(tornado,Gunicorn,Twisted,Gevent)
- 1、文件:
- 1)、代码结构:
- 2)、hello.py
- 3)、hello.html
- 2、flask 压力测试:
- 1)、执行hello.py【启动flask服务】
- 2)、siege测试
- 3、flask 打开自带的多线程
- 1)、修改代码
- 2)、压力测试
- 4、gunicorn 部署:
- 1)、gunicorn 部署
- 2)、压力测试:
- ①、w=1:
- ②、w=3
- ③、w=8
- 5、flask+gevent:
- 1)、hello-gevent.py
- 2)、压力测试:
- 6、tornado:
- 1)、代码:
- 2)、压测:
- 7、twist + flask
- 1)、服务代码:
- 2)、压测:
- 参考地址:
一、前言:
Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。(注意:Siege默认不支持https访问)
官方解释:【谷歌翻译过来的】
Siege 是一个 http 负载测试和基准测试工具。它旨在让 Web 开发人员在胁迫下测量他们的代码,以查看它如何在互联网上加载。Siege 支持基本身份验证、cookie、HTTP、HTTPS 和 FTP 协议。它允许用户访问具有可配置数量的模拟客户端的服务器。这些客户端将服务器置于“围攻之下”。
如果要支持https
需要安装openssl
cetos 安装:
参考这个:http://mrdede.com/?p=3410
但是我服务器安装之后,可以直接测试百度https的。
yum install openssl
git clone https://github.com/openssl/openssl
cd openssl
./config --prefix=/usr/local/openssl
make
make install
openssl version
二、安装使用:
文件备份:
https://wwa.lanzoui.com/b00v263be
密码:d75z
1、mac安装:
直接:
brew install siege
2、linux 安装:【centos 服务器】
想着mac可以直接brew安装,centos应该可以yum安装,结果还真的安装成功了。
yum install siege
通用Linux安装:
wget http://download.joedog.org/siege/siege-latest.tar.gz
tar zxvf siege-4.1.1.tar.gz
cd siege-4.1.1
make clean
./configure --prefix=/usr/local/siege --with-ssl=/usr/local/openssl
make
make install
3、window安装:
下周地址:官方未提供window版本。
去GitHub下周window版本:
下再之后,解压,把siege-windows目录移动到c磁盘.
C:\siege-windows。并吧C:\siege-windows目录放到系统环境path里面。
打开cmd就可以使用了。
4、测试百度:
参数:
siege -h
参数:
参数 描述
-V, –version 打印版本号
-h, –help 打印帮助信息
-C, –config 打印当前配置信息
-g, –get 拉取http头信息
-p, –print 打印整个页面的内容
-c, –concurrent=NUM 并发用户数量,默认10个
-r, –reps=NUM 运行次数
-d, –delay=NUM 随机时间延迟(秒)
-b, –benchmark 请求没有延迟
-i, –internet 模拟网络用户随机点击URL
-f, –file=FILE 选择指定的URL文件
-R, –rc=FILE 指定siegerc文件
-l, –log[=FILE] 日志文件,默认是 PREFIX/var/siege.log
-H, –header=”text” 给请求添加头,支持多个
-A, –user-agent=”text” 给请求设置User-Agent
-T, –content-type=”text” 给请求设置Content-Type
测试百度:
我这里设置3个并发,遍历3次,太多担心ip被封,无法测试。
一般可以使自己搭建web接口测试使用。
siege -c 3 -r 3 -b https://www.baidu.com/
最后返回结果:
Transactions: 270 hits
Availability: 100.00 %
Elapsed time: 5.26 secs
Data transferred: 4.01 MB
Response time: 0.06 secs
Transaction rate: 51.33 trans/sec
Throughput: 0.76 MB/sec
Concurrency: 2.95
Successful transactions: 270
Failed transactions: 0
Longest transaction: 0.90
Shortest transaction: 0.02
5、查看配置文件位置:
1)、siege -C
CURRENT SIEGE CONFIGURATION
Mozilla/5.0 (apple-x86_64-darwin20.4.0) Siege/4.1.1
Edit the resource file to change the settings.
----------------------------------------------
version: 4.1.1
verbose: true
color: true
quiet: false
debug: false
protocol: HTTP/1.1
HTML parser: enabled
get method: HEAD
connection: close
concurrent users: 25
time to run: n/a
repetitions: n/a
socket timeout: 30
cache enabled: false
accept-encoding: gzip, deflate
delay: 0.000 sec
internet simulation: false
benchmark mode: false
failures until abort: 1024
named URL: none
URLs file: /usr/local/Cellar/siege/4.1.1/etc/urls.txt
thread limit: 2550
logging: false
log file: /usr/local/var/log/siege.log
resource file: /Users/zjf228/.siege/siege.conf
timestamped output: false
comma separated output: false
allow redirects: true
allow zero byte data: true
allow chunked encoding: true
upload unique files: true
json output: false
no-follow:- ad.doubleclick.net- pagead2.googlesyndication.com- ads.pubsqrd.com- ib.adnxs.com
proxy auth:
www auth:
2)、找到后缀:siege.conf
配置文件就在这里面。我的是mac电脑。
/Users/zjf228/.siege/siege.conf
三、flask 四种wsgi方式对比(tornado,Gunicorn,Twisted,Gevent)
参考:https://blog.csdn.net/marscrazy_90/article/details/41943211
最后找到这一篇文章:
https://www.jianshu.com/p/d6961f713e46
1、文件:
1)、代码结构:
2)、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)
3)、hello.html
from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello World!</h1>
{% endif %}
2、flask 压力测试:
1)、执行hello.py【启动flask服务】
浏览器访问:http://127.0.0.1:13579/
2)、siege测试
经过测试,应该我这个电脑配置不高,还是设置为1000个用户,每个访问1次测试吧。
siege -c 1000 -r 1 -b http://127.0.0.1:13579/3344
返回最终压力测试结果:只有63%的成功率。
最高并发394.67。
Transactions: 783 hits
Availability: 78.30 %
Elapsed time: 2.66 secs
Data transferred: 0.03 MB
Response time: 1.34 secs
Transaction rate: 294.36 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 394.67
Successful transactions: 783
Failed transactions: 217
Longest transaction: 2.62
Shortest transaction: 0.32
3、flask 打开自带的多线程
1)、修改代码
# 1.threaded : 多线程支持,默认为False,即不开启多线程;
app.run(threaded=True)
# 2.processes:进程数量,默认为1.
app.run(processes=True)
ps:多进程或多线程只能选择一个,不能同时开启
app.run(host='0.0.0.0', port=13579,threaded=True, debug=False)
2)、压力测试
siege -c 1000 -r 1 -b http://127.0.0.1:13579/3344
返回的结果:
成功率反而降低了。
Transactions: 774 hits
Availability: 77.40 %
Elapsed time: 1.55 secs
Data transferred: 0.03 MB
Response time: 0.81 secs
Transaction rate: 499.35 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 405.55
Successful transactions: 774
Failed transactions: 226
Longest transaction: 1.45
Shortest transaction: 0.30
多进程:
Transactions: 728 hits
Availability: 72.80 %
Elapsed time: 1.28 secs
Data transferred: 0.03 MB
Response time: 0.74 secs
Transaction rate: 568.75 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 423.62
Successful transactions: 728
Failed transactions: 272
Longest transaction: 1.24
Shortest transaction: 0.28
4、gunicorn 部署:
1)、gunicorn 部署
pip install gunicorn
gunicorn -w 1 -b 127.0.0.1:13578 hello:app
# -w:后面是进程的个数,一般和自己服务器的核数一致。
# -b 是ip+端口号,13579,一直无法成功,之前的服务也关了,不知道为啥,干脆改了。
# hello:app 中,hello代表,hello.py文件,`:app`是固定格式,不动。
# 这个地方参考的作者没有写清楚,我还好之前用过几次。再不懂就百度gunicorn的用法吧。
先浏览器访问一下,还是可以的。
2)、压力测试:
siege -c 1000 -r 1 -b http://127.0.0.1:13578/3344
①、w=1:
Transactions: 501 hits
Availability: 50.10 %
Elapsed time: 1.59 secs
Data transferred: 0.02 MB
Response time: 0.99 secs
Transaction rate: 315.09 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 312.28
Successful transactions: 501
Failed transactions: 499
Longest transaction: 1.51
Shortest transaction: 0.00
②、w=3
Transactions: 608 hits
Availability: 60.80 %
Elapsed time: 1.32 secs
Data transferred: 0.02 MB
Response time: 0.57 secs
Transaction rate: 460.61 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 260.27
Successful transactions: 608
Failed transactions: 392
Longest transaction: 1.27
Shortest transaction: 0.00
③、w=8
Transactions: 578 hits
Availability: 57.80 %
Elapsed time: 1.53 secs
Data transferred: 0.02 MB
Response time: 0.99 secs
Transaction rate: 377.78 trans/sec
Throughput: 0.01 MB/sec
Concurrency: 372.63
Successful transactions: 578
Failed transactions: 422
Longest transaction: 1.51
Shortest transaction: 0.00
5、flask+gevent:
安装gevent模块:
pip install gevent
1)、hello-gevent.py
from gevent import monkey
monkey.patch_all()
from gevent.pywsgi import WSGIServerfrom flask import Flask, render_templateapp = Flask(__name__)@app.route('/')
@app.route('/<name>')
def index(name=None):return render_template('hello.html', name=name)if __name__== '__main__':# app.run()# app.run(host='0.0.0.0', port=13579, debug=False)http_server = WSGIServer(('127.0.0.1', int(13579)), app)http_server.serve_forever()
2)、压力测试:
成功率,有98%,99%,89%,取最后一次,发现,效果确实提升了不少。
不知道原作者前几个怎么高的,我的咋差别这么多。
siege -c 1000 -r 1 -b http://127.0.0.1:13579/3344
Transactions: 955 hits
Availability: 95.50 %
Elapsed time: 1.23 secs
Data transferred: 0.04 MB
Response time: 0.71 secs
Transaction rate: 776.42 trans/sec
Throughput: 0.03 MB/sec
Concurrency: 550.13
Successful transactions: 955
Failed transactions: 45
Longest transaction: 1.13
Shortest transaction: 0.16
6、tornado:
1)、代码:
# -*- coding: utf-8 -*-import loggingfrom tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.options import define, optionsdefine('port', type=int, default=13579)
# deploy or debug
define('mode', default='debug')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) def main():options.parse_command_line()http_server = HTTPServer(WSGIContainer(app))http_server.listen(options.port)logging.info("[UOP] App is running on: localhost:%d" % options.port)IOLoop.instance().start()if __name__ == '__main__':main()
直接跑这个py文件即可:
2)、压测:
siege -c 1000 -r 1 -b http://127.0.0.1:13579/3344
这个也是不固定值,这个可能和我的办公电脑有关吧。。。
Transactions: 863 hits
Availability: 86.30 %
Elapsed time: 1.34 secs
Data transferred: 0.04 MB
Response time: 0.82 secs
Transaction rate: 644.03 trans/sec
Throughput: 0.03 MB/sec
Concurrency: 526.29
Successful transactions: 863
Failed transactions: 137
Longest transaction: 1.30
Shortest transaction: 0.21
7、twist + flask
1)、服务代码:
from flask import Flask
from flask import render_template # pip install Flask-Twisted
from flask_twisted import Twisted
#from flask.ext.twisted import Twistedapp = Flask(__name__)@app.route('/')
@app.route('/<name>')
def index(name=None): print('come into index')return render_template('hello.html', name=name) twisted = Twisted(app)if __name__ == "__main__":print('come into main')#app.run()twisted.run(host='0.0.0.0',port=13579, debug=False) #app.run(host='0.0.0.0',port=13579, debug=False)
直接运行脚本
2)、压测:
siege -c 1000 -r 1 -b http://127.0.0.1:13579/3344
平均在80%左右。
Transactions: 778 hits
Availability: 77.80 %
Elapsed time: 1.62 secs
Data transferred: 0.04 MB
Response time: 1.21 secs
Transaction rate: 480.25 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 578.83
Successful transactions: 778
Failed transactions: 222
Longest transaction: 1.58
Shortest transaction: 0.65
参考地址:
https://www.dazhuanlan.com/shsunyang/topics/932282
https://github.com/ewwink/siege-windows
http://mrdede.com/?p=3410
https://blog.csdn.net/wsliangjian/article/details/47147827
https://blog.csdn.net/funnyPython/article/details/78824598
https://www.joedog.org/siege-home/
http://download.joedog.org/siege/
https://blog.csdn.net/u011466469/article/details/88593043
https://blog.csdn.net/marscrazy_90/article/details/41943211
https://zhuanlan.zhihu.com/p/131364462
独立 WSGI 容器
http://docs.jinkan.org/docs/flask/deploying/wsgi-standalone.html
Siege压力测试工具的安装及使用+python flask的四种wsgi方式对比相关推荐
- Siege压力测试工具安装与使用
Siege是linux下的一个web系统的压力测试工具,可以对web系统进行多并发下持续请求的压力测试. 在ubuntu上安装命令: sudo apt-get install siege 运行sieg ...
- python的web压力测试工具-pylot安装使用
pylot是python编写的一款web压力测试工具.使用比较简单.而且测试结果相对稳定. 这里不得不鄙视一下apache 的ab测试,那结果真是让人蛋疼,同样的url,测试结果飘忽不定,看得人心惊肉 ...
- 网站压力测试工具webbench 安装与使用
webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好用,安装使用也特别方便,并且非常小. 主要是 -t 参数用着比较爽,下面参考了张宴的文章 ...
- siege压力测试工具安装和介绍
前言 最近公司有个项目需要做一个短轮询类推送服务器(推送服务器分为三种,短轮询,长轮询,长连接),用户量不大,但是为了保险起见还是做一下压力测试.用的工具是siege. 目录 前言 目录 siege介 ...
- 压力测试工具gatling安装和介绍
Gatling主要用于测量基于HTTP的服务器,比如Web应用程序,RESTful服务等. 1 优点: 1.gatling和其他压力工具相比有个好处是放在同一内网环境下linux服务器上,这样避免其他 ...
- web压力测试工具ab安装及使用
## 安装 brew install aprbrew install apr-utilbrew install openssl --upgradewget http://mirrors.tuna.t ...
- 压力测试工具Jemeter安装及使用
1.Jemeter下载(官网下载),需先配置好JDK(网上教程一大把,不赘述) 如果嫌麻烦,本人网盘下载:https://pan.baidu.com/s/1B1d0Et9gS4Rjqu-UEkq1Xw ...
- linux分区压力测试,stress-Linux系统压力测试工具使用及系统负载很高的几种场景测试...
安装 yum install stress stress-ng -y stess-ng是stress的下一代,功能更加完善 常用选项 -c,--cpu:代表进程个数(每个进程会占用一个cpu,当超出c ...
- python的ols_【量化工具】OLS在python中的四种实现方式
在p-quant中,线性回归应该是最最最重要的统计方法了,没有之一:OLS又是线性回归中最常见的形式,在python中可以利用多个方法来实现 考虑线性回归如下形式 一.sklearn from skl ...
最新文章
- 2022-2028全球与中国跨临界二氧化碳系统市场现状及未来发展趋势报告
- MIT自动驾驶船下水!可乘坐5人,阿姆斯特丹运河航行3小时误差不到0.17米
- java callback 多线程_JAVA Callback效率测试
- HDU 4422 The Little Girl who Picks Mushrooms(简单题)
- 『无聊透顶』一篇很无聊的文章
- 《数学之美》—信息的度量和作用
- Vue中解决移动端点击300毫秒延迟的问题
- c语言源程序的基础单位,c源程序的基本单位是什么
- 网页右侧在线客服html,漂浮在网页右侧的QQ在线客服代码? 1、怎么样修改以下代码,让其变为最靠右边2、如何插入到网页当中...
- AI英雄 | 论人工智能与自由意志,请看尤瓦尔与李飞飞的这场“激辩”
- 当自己觉得特别迷茫的时候,是怎么走出这个困境的
- 一元三次方程重根判别式_一元三次方程的判别式和求根公式是什么?
- JAVA中关于if结构的相关的练习题
- 未来富豪,将出自这12大颠覆性领域
- Failed to initiate the GitHub login process. Please try again(1.1.25.1678)
- 面试太卷,我选择背八股。。。
- 伪漫迷用数据假装看了一遍《复联4》
- ALK8266WIFI解决方案支持常见普通单片机实现WIFI高速传输和许多实用功能,实测速度超过M字节每秒
- 1258:数字金字塔
- 语音识别karas实现
热门文章
- 如何将Word快速转为PPT?
- C#让TextBox滚动条一直位于最下部
- T5L芯片做主控在车载控制器行业的应用
- 阿里云的手机短信验证
- java sortable_如何在Jquery Sortable中将嵌套列表li限制为仅两个级别?
- Lingo运输+选址问题
- Android7.1上报的CNEService/WbcService/LauncherUnreadService停止运行错误,拔掉电池重启开机几次才不报
- 汉明距离(Hamming Distance)
- 【天池龙珠计划寒假训练营】python学习笔记(三):从函数到高级魔法方法
- dnf进游戏找不到服务器,进游戏卡在正在连接服务器,求救!!