记录:Web服务器压力测试工具WebBench、Siege

Posted by Leon on 2016-03-07

记录 WebBench、Siege服务器压力测试工具说明以及使用。

WenBench

WebBench是一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力。

##下载安装:

1
2
# git clone https://github.com/EZLippi/WebBench.git
# sudo make && make install

##命令行选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-f|--force               Don't wait for reply from server.
-r|--reload Send reload request - Pragma: no-cache.
-t|--time <sec> Run benchmark for <sec> seconds. Default 30.
-p|--proxy <server:port> Use proxy server for request.
-c|--clients <n> Run <n> HTTP clients at once. Default one.
-9|--http09 Use HTTP/0.9 style requests.
-1|--http10 Use HTTP/1.0 protocol.
-2|--http11 Use HTTP/1.1 protocol.
--get Use GET request method.
--head Use HEAD request method.
--options Use OPTIONS request method.
--trace Use TRACE request method.
-?|-h|--help This information.
-V|--version Display program version.

#Siege

一款开源的压力测试工具,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。

安装使用

1
2
3
4
5
# wget http://download.joedog.org/siege/siege-latest.tar.gz
# tar -zxvf siege-latest.tar.gz
# cd siege-latest/
# ./configure
# make && make install

相关命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-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
-i, --internet INTERNET user simulation, hits URLs randomly.
-b, --benchmark BENCHMARK: no delays between requests.
-t, --time=NUMm TIMED testing where "m" is modifier S, M, or H
ex: --time=1H, one hour test.
-r, --reps=NUM REPS, number of times to run the test.
-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.
-d, --delay=NUM Time DELAY, random delay before each requst
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

使用举例

1000个并发访问http://www.youku.com并重复请求100次

1
siege -c 1000 -r 100 http://www.youku.com

在urls.txt中列出所有的网址

1
siege -c 200 -r 100 -f urls.txt

随机选取urls.txt中列出所有的网址

1
siege -c 200 -r 100 -f urls.txt -i

不等待返回结果,2000个并发随机选取urls.txt重复请求100个

1
siege -c 2000 -r 100 -f urls.txt -i -b

指定http请求头请求

1
siege -H "Content-Type:application/json" -c 200 -r 100 -f urls.txt -i -b

POST请求

1
siege -c 1000 -r 100 http://www.a.com/ POST p1=v1&p2=v2

Siege输出结果说明

Transactions: 总共测试次数
Availability: 成功次数百分比
Elapsed time: 总共耗时多少秒
Data transferred: 总共数据传输
Response time: 等到响应耗时
Transaction rate: 平均每秒处理请求数
Throughput: 吞吐率
Concurrency: 最高并发
Successful transactions: 成功的请求数
Failed transactions: 失败的请求数