压力测试工具的下载和使用

本文最后更新于:December 3, 2021 pm

目录

1.WebBench

1
2
3
4
5
wget http://www.ha97.com/webbench-1.5.tar.gz
tar -zxvf webbench-1.5.tar.gz
cd webbench-1.5
make
make install

安装中遇到的问题如下:

1
2
3
ctags *.c 
/bin/sh: ctags: command not found
make: [tags] Error 127 (ignored)

缺少ctags命令,用apt install ctags安装即可。

1
2
apt install ctags //ubuntu
yum install ctags //centos

测试webbench:

1
webbench 

实战:

1
webbench -c 1000 -t 60 http://192.168.80.157/phpinfo.php //1000个并发,执行60秒

参数说明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
webbench [option]... URL
-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.

结果说明:

1
2
每秒钟响应请求数:24525 pages/min,每秒钟传输数据量20794612 bytes/sec.
并发1000运行60秒后产生的TCP连接数12000多个,已经显示有87个连接failed了,说明超负荷了。

2.Siege

Siege是一款高性能的Http压力测试工具。
Siege支持身份验证、cookies、http、https和ftp协议。
支持多链接,支持get和post请求,可以对web系统进行多并发下持续请求的压力测试。

1
2
3
4
5
6
7
8
cd /usr/local/src
wget http://download.joedog.org/siege/siege-4.0.4.tar.gz
tar -zxvf siege-4.0.4.tar.gz
cd siege-4.0.4/
./configure --prefix=/usr/local/siege
make && make install
#将命令加入全局
ln -s /usr/local/siege/bin/siege /usr/bin/siege

示例:

1
siege -c 200 -r 100 http://www.google.com //200个并发,请求100次

注意:siege默认只支持255个并发数,可以自己自定义,修改/root/.siege/siege.conf下的limit数值。

3.Jmeter

前提环境:需要java环境(配置jdk),可见《星星之火-实现一台服务器跑多个项目 》一文。

安装:

1
2
wget https://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-5.2.1.tgz
tar -zxvf apache-jmeter-5.2.1.tgz

也可以自行下载安装包再上传到服务器后,再解压。
解压完后,添加环境变量。

1
vi /etc/profile

将以下内容输入进去:

1
2
3
4
5
6
export JMETER_HOME=/root/apache-jmeter-5.2.1

export CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$CLASSPATH

export PATH=$JMETER_HOME/bin:$PATH

让配置生效:

1
source /etc/profile 

再输入jmeter检验是否成功。