web服务器性能测试的工具有很多,比如ab,siege等,小组使用siege测试工具进行性能测试。
Siege基本上有三种操作模式,回归,互联网模拟和暴力。它可以从配置文件中读取大量URL,并逐个或随机运行它们,或者用户可以在命令行中使用命令行简单地敲击单个URL;
安装包安装
wget http://download.joedog.org/siege/siege-latest.tar.gz
$ tar zxf siege-latest.tar.gz
$ cd siege-4.0.2/
$ ./configure
$ sudo make
$ sudo make install
命令行
yum install siege
或者
apt install siege
查看是否安装成功:
查看siege安装路径:
$ which siege
/usr/local/bin/siege
查看siege版本:
$ siege -V
SIEGE 4.0.2
SIEGE 4.0.2
Usage: siege [options]
siege [options] URL
siege -g URL
Options:
-V, --version VERSION, prints the version number.
-h, --help HELP, prints this section.
-C, --config CONFIGURATION, show the current config.
-v, --verbose VERBOSE, prints notification to screen.
-q, --quiet QUIET turns verbose off and suppresses output.
-g, --get GET, pull down HTTP headers and display the
transaction. Great for application debugging.
-c, --concurrent=NUM CONCURRENT users, default is 10
-r, --reps=NUM REPS, number of times to run the test.
-t, --time=NUMm TIMED testing where "m" is modifier S, M, or H
ex: --time=1H, one hour test.
-d, --delay=NUM Time DELAY, random delay before each requst
-b, --benchmark BENCHMARK: no delays between requests.
-i, --internet INTERNET user simulation, hits URLs randomly.
-f, --file=FILE FILE, select a specific URLS FILE.
-R, --rc=FILE RC, specify an siegerc file
-l, --log[=FILE] LOG to FILE. If FILE is not specified, the
default is used: PREFIX/var/siege.log
-m, --mark="text" MARK, mark the log file with a string.
between .001 and NUM. (NOT COUNTED IN STATS)
-H, --header="text" Add a header to request (can be many)
-A, --user-agent="text" Sets User-Agent in request
-T, --content-type="text" Sets Content-Type in request
当服务启动后,就可以测试调用了:
GET请求方式调用
单条地址重复测试:
siege -r 10 -c 25 http://0.0.0.0:5000/xxx?user=10
文件测试:文件里面准备好的多条访问地址,可以通过参数控制选择是逐条测试或者随机测试:
siege -c 15 -r 50 -b -f test_file &> log.press.$RANDOM &
POST请求方式调用
单条地址重复测试:
siege -H "Content-Type:application/json" -c 10 -r 10 http://0.0.0.0:5000/xxx POST p1=v1&p2=v2
json文件测试
# 新建json文件
# 1.vim test.json
{
"p1": p1,
"p2": p2
}
# 2. 测试语句
# 每秒10个并发跑10次 test.json 为发送的数据内容
siege -H "Content-Type:application/json" -c 10 -r 10 "http://0.0.0.0:5000/xxx POST < /tmp/test.json"
注意:如果url中含有空格和中文,要先进行url编码,否则siege发送的请求url不准确
-c25:25个仿真用户,-r10:每个用户请求的次数;Transactions:服务器受到的请求次数;Elapsedtime:整个测试阶段总耗时;Datatransferred:每个仿真用户传输数据大小的总和;Responsetime:每次请求耗时的平均时间;Transactionrate:服务器每秒能够处理的请求数量;Throughput:服务器每秒传输的字节数;Concurrency:平均同时连接数;Successfultransactions:成功连接次数;Failedtransactions:失败连接次数;Longesttransactions:最长的一次请求时间;Shortesttransactions:最短的一次请求时间;
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点