Mac 安装
// Mac自带了apache 所以不需要安装
Linux
yum install httpd -y
// 或者, ab可以不依赖apache
yum install apache2-util2
// 或者用源码包安装
安装好了命令行输入"ab", 如果打印出帮助命令说明安装成功
-V, 查看ab版本
ab -V
–help, 查看ab帮助命令说明
// 下面2条命令都可以, 习惯第一条
ab
ab --help
-n, 请求个数,默认一次
进行了10次请求
ab -n 10 http://localhost:3003/test/
-t, 测试时最大秒数, 默认没有时间限制
10秒给你返回结果
ab -t 10 http://localhost:3003/test/
-c, 每次请求并发多少次, 默认一次, 配合-t
ab -c 10 -t 5 http://localhost:3003/test/
-s, 等待每个响应最大秒数, 默认是30秒
ab -s 10 http://localhost:3003/test/
-m, 请求方法, 默认GET
必须大写
ab -m "POST" http://localhost:3003/test/
-C, 发送cookie,多个字段用分号;
ab -C "username=admin; password=root" http://localhost:3003/test/
-H, 发送头信息
ab -H "Content-Type: text/html" http://localhost:3003/test/
下面说一下输出信息
xiejiahe$ ab http://localhost:3003/test/
输出以下信息
// 服务器,显示了空说明没有测到
Server Software:
// 测试网站的hostname
Server Hostname: localhost
// 网站端口
Server Port: 3003
// 网站路径
Document Path: /test/
// 文档字节大小,后台 echo 'hello ab';
Document Length: 8 bytes
// 并发一次, 等于 -c 1
Concurrency Level: 1
// 花了0.006秒测试时间
Time taken for tests: 0.006 seconds
// 请求了一次, 等于 -n 1
Complete requests: 1
// 失败请求0次
Failed requests: 0
// 总共网络传输量字节
Total transferred: 206 bytes
// 总共HTML传输量字节
HTML transferred: 8 bytes
// 每秒请求177次
Requests per second: 177.75 [#/sec] (mean)
// 用户5.626毫秒请求一次
Time per request: 5.626 [ms] (mean)
// 服务器每次5.626毫秒处理时间
Time per request: 5.626 [ms] (mean, across all concurrent requests)
// 平均每秒传输速率
Transfer rate: 35.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 5 5 0.0 5 5
Waiting: 5 5 0.0 5 5
Total: 6 6 0.0 6 6
常用的也就是-c -n
请求10次,每次请求10次并发
ab -c 10 -n 10 http://localhost:3003/test/
注意了网站后面要带斜杠/, 否则无法测试
错误
http://localhost:3003
正确
http://localhost:3003/