安装
yum -y install httpd-tools
基本用法
- 100w请求,400并发测试。
$ ab -c 400 -n 1000000 http://localhost:8888/bm/redis/put/100
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) #压测进度
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests
Server Software:
Server Hostname: localhost
Server Port: 8888
Document Path: /bm/redis/put/100
Document Length: 16 bytes
Concurrency Level: 400
Time taken for tests: 155.041 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 95000000 bytes
HTML transferred: 16000000 bytes
Requests per second: 6449.92 [#/sec] (mean)
Time per request: 62.016 [ms] (mean)
Time per request: 0.155 [ms] (mean, across all concurrent requests)
Transfer rate: 598.38 [Kbytes/sec] received
Connection Times (ms) #请求处理分析
min mean[+/-sd] median max
Connect: 0 41 237.0 0 15035
Processing: 0 21 12.8 20 1618
Waiting: 0 21 12.8 20 1618
Total: 0 62 238.7 20 15056
Percentage of the requests served within a certain time (ms) #请求时间百分比分布
50% 20
66% 21
75% 22
80% 22
90% 24
95% 30
98% 1022
99% 1025
100% 15056 (longest request) #最大请求时间
其他参数
Options are:
-n requests 本次总请求数
-c concurrency 并发数
-t timelimit 基础压测最大时间(秒),基于-n 50000的情况下最大测试时间,默认不显示。
-s timeout 请求超时时间(秒),默认30秒
-b windowsize 缓冲区大小(字节)
-B address Address to bind to when making outgoing connections
-p postfile POST请求文件,需要设置 -T
-u putfile PUT请求文件. 需要设置 -T
-T content-type POST/PUT请求header中的content-type值,默认是'text/plain'
-v verbosity 显示多少故障信息,1/2/3/4
-w 在html中显示结果
-i 使用head请求,默认是get
-x attributes 设置table属性
-y attributes 设置tr属性
-z attributes 设置th属性
-C attribute 添加cookie, 如:'Apache=1234',可重复
-H attribute 添加header, 如:'Accept-Encoding: gzip',追加常规header后面,可重复。
-A attribute 添加WWW认证信息, 格式'user:pwd'
-P attribute 添加基础身份认证信息,格式'user:pwd'
-X proxy:port 使用的代理服务端口
-V 显示版本
-k 使用http连接保持功能
-d 不显示时间百分比分布.
-S 不显示中位数和警告
-q 总请求数大于150时,不显示测试请求进度(Benchmarking localhost)。
-g filename 输出测试数据到指定文件.
-e filename 输出百分比CSV文件
-r 收到错误信息不退出
-h 显示帮助信息
-Z ciphersuite 指定SSL/TLS密码套件,参考openssl
-f protocol 指定SSL/TLS协议,如:(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)