性能工具之ab压力测试工具及ab命令详解

不操千曲而后晓声,观千剑而后识器。这篇文章主要讲述性能工具之ab压力测试工具及ab命令详解相关的知识,希望能为你提供帮助。
背景安装

  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. [root@7dgroup2 ~]# ab help
  7. ab: invalid URL
  8. Usage: ab [options] [http[s]://]hostname[:port]/path
  9. Options are:
  10. -n requestsNumber of requests to perform
  11. -c concurrencyNumber of multiple requests to make at a time
  12. -t timelimitSeconds to max. to spend on benchmarking
  13. This implies -n 50000
  14. -s timeoutSeconds to max. wait for each response
  15. Default is 30 seconds
  16. -b windowsizeSize of TCP send/receive buffer, in bytes
  17. -B addressAddress to bind to when making outgoing connections
  18. -p postfileFile containing data to POST. Remember also to set -T
  19. -u putfileFile containing data to PUT. Remember also to set -T
  20. -T content-type Content-type header to use for POST/PUT data, eg.
  21. \'application/x-www-form-urlencoded\'
  22. Default is \'text/plain\'
  23. -v verbosityHow much troubleshooting info to print
  24. -wPrint out results in html tables
  25. -iUse HEAD instead of GET
  26. -x attributesString to insert as table attributes
  27. -y attributesString to insert as tr attributes
  28. -z attributesString to insert as td or th attributes
  29. -C attributeAdd cookie, eg. \'Apache=1234\'. (repeatable)
  30. -H attributeAdd Arbitrary header line, eg. \'Accept-Encoding: gzip\'
  31. Inserted after all normal header lines. (repeatable)
  32. -A attributeAdd Basic WWW Authentication, the attributes
  33. are a colon separated username and password.
  34. -P attributeAdd Basic Proxy Authentication, the attributes
  35. are a colon separated username and password.
  36. -X proxy:portProxyserver and port number to use
  37. -VPrint version number and exit
  38. -kUse HTTP KeepAlive feature
  39. -dDo not show percentiles served table.
  40. -SDo not show confidence estimators and warnings.
  41. -qDo not show progress when doing more than 150 requests
  42. -g filenameOutput collected data to gnuplot format file.
  43. -e filenameOutput CSV file with percentages served
  44. -rDon\'t exit on socket receive errors.
  45. -hDisplay usage information (this message)
  46. -Z ciphersuiteSpecify SSL/TLS cipher suite (See openssl ciphers)
  47. -f protocolSpecify SSL/TLS protocol
  48. (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
  49. [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. Benchmarking 172.17.211.142 (be patient).....done
  6. Server Software:#服务器软件
  7. Server Hostname:172.17.211.142 #域名
  8. Server Port:8089#请求端口号
  9. Document Path:/#文件路径
  10. Document Length:76443 bytes#页面字节数
  11. Concurrency Level:10#请求的并发数
  12. Time taken for tests:0.064 seconds#总访问时间
  13. Complete requests:10#请求成功数量
  14. Failed requests:0#请求失败数量
  15. Write errors:0
  16. Total transferred:766030 bytes #请求总数据大小(包括header头信息)
  17. HTML transferred:764430 bytes#html页面实际总字节数
  18. Requests per second:157.09 [#/sec] (mean)#每秒多少请求,服务器的吞吐量
  19. Time per request:63.656 [ms] (mean)#用户平均请求等待时间
  20. Time per request:6.366 [ms] (mean, across all concurrent requests) # 服务器平均处理时间,也就是服务器吞吐量的倒数
  21. Transfer rate:11751.86 [Kbytes/sec] received#每秒获取的数据长度
  22. Connection Times (ms)
  23. minmean[+/-sd] medianmax
  24. Connect:000.000#网络链接
  25. Processing:83617.14160#系统处理
  26. Waiting:32418.71855#等待
  27. Total:93717.14260
  28. #Total并不等于前三行数据相加,因为前三行的数据并不是在同一个请求中采集到的,
  29. #可能某个请求的网络延迟最短,但是系统处理时间又是最长的呢。
  30. #所以Total是从整个请求所需要的时间的角度来统计的。
  31. Percentage of the requests served within a certain time (ms)
  32. 50%42
  33. 66%45
  34. 75%51
  35. 80%52
  36. 90%60
  37. 95%60
  38. 98%60
  39. 99%60
  40. 100%60 (longest request)
【性能工具之ab压力测试工具及ab命令详解】

    推荐阅读