和后端的小伙伴交流,讨论node、python、go搭建的web服务的性能,需要对服务器进行压力测试,朋友推荐了Apache的ab,我这里介绍的是webbench和Siege(Mac上面使用 window和linux百度自行解决)

第一步: 安装webbench:

先安装依赖:

1
brew install ctags

下载并安装:

1
2
3
4
5
wget http://blog.zyan.cc/soft/linux/webbench/webbench-1.5.tar.gz
tar -zxf webbench-1.5.tar.gz
cd webbench-1.5
sudo mkdir -pv /usr/local/man/man1
sudo make && sudo make install

使用: webbench -c 并发数 -t 运行测试时间 URL
eg: webbench -t 60 -c 100 http://www.baidu.com/

安装Siege:

1
2
3
4
5
6

wget http://download.joedog.org/siege/siege-latest.tar.gz
tar -zxvf siege-latest.tar.gz
cd siege-* # 这里需要查看解压的目录
./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

eg: 1000个人,没人请求100次,测试5秒钟
siege -c 1000 -r 100 -t 5s http://www.youku.com