wrk2
wrk2是基于wrk进行修改的HTTP基准测试工具,主要用于产生恒定吞吐量的负载,并提供准确的延迟信息,可以精确到高百万分之一的百分位数(即在足够长时间运行时可以产生准确的99.9999%百分位数)。除了wrk的参数外,wrk2还通过–rate或-R参数接受吞吐量参数(以总请求每秒为单位),默认值为1000。
安装
Ubuntu/Debian (clean box)
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev git zlib1g-dev
sudo git clone https://github.com/giltene/wrk2.git
cd wrk2
sudo make
#move the executable to somewhere in your PATH
sudo cp wrk /usr/local/bin
CentOS / RedHat / Fedora
sudo yum -y groupinstall ‘Development Tools’
sudo yum -y install openssl-devel git zlib-devel
git clone https://github.com/giltene/wrk2.git
cd wrk2
make
#move the executable to somewhere in your PATH
#to find your PATH
sudo echo $PATH
#Select appropriate PATH
#CentOS 7 with cPanel PATH example: sudo cp wrk /usr/local/bin
sudo cp wrk /somewhere/in/your/PATH
命令
wrk -t2 -c100 -d30s -R2000 http://127.0.0.1:8080/index.html
这将运行基准测试30秒,使用2个线程,保持100个HTTP连接打开,以及每秒2000个请求的恒定吞吐量(总计,跨所有连接组合)。
[需要注意的是,wrk2 将初始校准周期从 wrk 的 0.5 秒延长到 10 秒,因此短于 10-20 秒的运行可能不会提供有用的信息]
配合lua脚本
# data.json
wrk.method = "POST"
wrk.headers["content-type"] = "application/json"
wrk.body = "{\"name\": \"postman-{{$guid}}\",\"cost\":100}"
# script
wrk -t2 -c10 -d30s -R100 http://10.24.229.52:8080/debug/ping
wrk -t5 -d30s -c100 -R500 -s data.lua -L http://10.24.229.52:8080/debug/hello
wrk -t5 -d30s -c200 -R1000 -s data.lua -L http://10.24.229.52:8080/debug/hello
wrk -t5 -d30s -c300 -R2000 -s data.lua -L http://10.24.229.52:8080/debug/hello
wrk -t5 -d30s -c400 -R3000 -s data.lua -L http://10.24.229.52:8080/debug/hello
wrk -t5 -d30s -c600 -R4000 -s data.lua -L http://10.24.229.52:8080/debug/hello
Apache Bench
Apache Bench或简称ab是一个命令行工具,用于在HTTP服务器上执行简单的负载测试,无论是网站还是API
安装
Ubuntu/Debian (clean box)
apt-get update
apt-get install apache2-utils
CentOS / RedHat / Fedora
sudo yum install httpd-tools
命令
-n: Number of requests
-c: Number of concurrent requests
-H: Add header
—r: flag to not exit on socket receive errors
-k: Use HTTP KeepAlive feature
-p: File containing data to POST
-T: Content-type header to use for POST/PUT data,
post脚本
# install apache bench
yum install httpd-tools
# data.json
{"name": "postman-{{$guid}}","cost":100}
# script
ab -n 20000 -c 50 -p data.json -T application/json -rk http://10.24.229.52:8080/debug/hello
ab -n 40000 -c 100 -p data.json -T application/json -rk http://10.24.229.52:8080/debug/hello
ab -n 80000 -c 200 -p data.json -T application/json -rk http://10.24.229.52:8080/debug/hello
ab -n 120000 -c 300 -p data.json -T application/json -rk http://10.24.229.52:8080/debug/hello
ab -n 160000 -c 400 -p data.json -T application/json -rk http://10.24.229.52:8080/debug/hello