背景

ab小型压力工具,对于在Linux中简单调试还是比较方便,轻巧灵活.

安装

  1. yum -y install httpd-tools

查看版本

  1. [root@7dgroup2 ~]# ab -V
  2. This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/
  5.  
  6. 帮助
  7. [root@7dgroup2 ~]# ab help
  8. ab: invalid URL
  9. Usage: ab [options] [http[s]://]hostname[:port]/path
  10. Options are:
  11. -n requests Number of requests to perform
  12. -c concurrency Number of multiple requests to make at a time
  13. -t timelimit Seconds to max. to spend on benchmarking
  14. This implies -n 50000
  15. -s timeout Seconds to max. wait for each response
  16. Default is 30 seconds
  17. -b windowsize Size of TCP send/receive buffer, in bytes
  18. -B address Address to bind to when making outgoing connections
  19. -p postfile File containing data to POST. Remember also to set -T
  20. -u putfile File containing data to PUT. Remember also to set -T
  21. -T content-type Content-type header to use for POST/PUT data, eg.
  22. 'application/x-www-form-urlencoded'
  23. Default is 'text/plain'
  24. -v verbosity How much troubleshooting info to print
  25. -w Print out results in HTML tables
  26. -i Use HEAD instead of GET
  27. -x attributes String to insert as table attributes
  28. -y attributes String to insert as tr attributes
  29. -z attributes String to insert as td or th attributes
  30. -C attribute Add cookie, eg. 'Apache=1234'. (repeatable)
  31. -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
  32. Inserted after all normal header lines. (repeatable)
  33. -A attribute Add Basic WWW Authentication, the attributes
  34. are a colon separated username and password.
  35. -P attribute Add Basic Proxy Authentication, the attributes
  36. are a colon separated username and password.
  37. -X proxy:port Proxyserver and port number to use
  38. -V Print version number and exit
  39. -k Use HTTP KeepAlive feature
  40. -d Do not show percentiles served table.
  41. -S Do not show confidence estimators and warnings.
  42. -q Do not show progress when doing more than 150 requests
  43. -g filename Output collected data to gnuplot format file.
  44. -e filename Output CSV file with percentages served
  45. -r Don't exit on socket receive errors.
  46. -h Display usage information (this message)
  47. -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
  48. -f protocol Specify SSL/TLS protocol
  49. (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
  50. [root@7dgroup2 ~]#
  • -n在测试会话中所执行的请求个数。默认时,仅执行一个请求。

  • -c一次产生的请求个数。默认是一次一个。

  • -t测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

快速上手

  1. [root@7dgroup2 ~]# ab -n10 -c 10 http://172.17.211.142:8089/
  2. This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking 172.17.211.142 (be patient).....done
  7.  
  8.  
  9. Server Software: #服务器软件
  10. Server Hostname: 172.17.211.142 #域名
  11. Server Port: 8089 #请求端口号
  12.  
  13. Document Path: / #文件路径
  14. Document Length: 76443 bytes #页面字节数
  15.  
  16. Concurrency Level: 10 #请求的并发数
  17. Time taken for tests: 0.064 seconds #总访问时间
  18. Complete requests: 10 #请求成功数量
  19. Failed requests: 0 #请求失败数量
  20. Write errors: 0
  21. Total transferred: 766030 bytes #请求总数据大小(包括header头信息)
  22. HTML transferred: 764430 bytes #html页面实际总字节数
  23. Requests per second: 157.09 [#/sec] (mean) #每秒多少请求,服务器的吞吐量
  24. Time per request: 63.656 [ms] (mean) #用户平均请求等待时间
  25. Time per request: 6.366 [ms] (mean, across all concurrent requests) # 服务器平均处理时间,也就是服务器吞吐量的倒数
  26. Transfer rate: 11751.86 [Kbytes/sec] received #每秒获取的数据长度
  27.  
  28. Connection Times (ms)
  29. min mean[+/-sd] median max
  30. Connect: 0 0 0.0 0 0 #网络链接
  31. Processing: 8 36 17.1 41 60 #系统处理
  32. Waiting: 3 24 18.7 18 55 #等待
  33. Total: 9 37 17.1 42 60
  34. #Total并不等于前三行数据相加,因为前三行的数据并不是在同一个请求中采集到的,
  35. #可能某个请求的网络延迟最短,但是系统处理时间又是最长的呢。
  36. #所以Total是从整个请求所需要的时间的角度来统计的。
  37. Percentage of the requests served within a certain time (ms)
  38. 50% 42
  39. 66% 45
  40. 75% 51
  41. 80% 52
  42. 90% 60
  43. 95% 60
  44. 98% 60
  45. 99% 60
  46. 100% 60 (longest request)