1. 程式人生 > >Apache Bench——ab效能測試工具

Apache Bench——ab效能測試工具

ab是一種用於測試Apache超文字傳輸協議(HTTP)伺服器的工具。apache自帶ab工具,可以測試
apache、IIs、tomcat、nginx等伺服器
但是ab沒有Jmeter、Loadrunner那樣有各種場景設計、各種圖形報告和監控,只需一個命令即可,有輸出描述
可以簡單的進行一些壓力測試

一、Mac下自帶apache
檢視版本 apachectl -v

以請求百度為例:http://httpd.apache.org/docs/2.4/programs/ab.html 詳細說明見官網
ab命令同時滿足http及https的請求
常用請求引數:-n請求次數,-c併發數
Wx-MacBookPro:apache2 wuxi$ ab -n 100 -c 10 https://www.baidu.com/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
//apache版本資訊
Benchmarking www.baidu.com (be patient).....done


Server Software: BWS/1.1
//請求返回header型別,可能是nginx、apache、IIs等
Server Hostname: www.baidu.com
//請求ip或者域名
Server Port: 443
//請求埠,當前請求為https所以埠為443,請求https埠80
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
//https埠協議
TLS Server Name: www.baidu.com

Document Path: /
//路徑
Document Length: 227 bytes
//第一個成功返回的文件的位元組大小
Concurrency Level: 10
//併發數!!!
Time taken for tests: 1.034 seconds
//從建立連線到最後接受完成總時間
Complete requests: 100
//總請求數成功的
Failed requests: 0
//失敗的
Total transferred: 87200 bytes
//從伺服器接收的位元組總數
HTML transferred: 22700 bytes
//HTML接收位元組數
Requests per second: 96.75 [#/sec] (mean)
————每秒請求數(總請求數/總時間)
Time per request: 103.359 [ms] (mean)
————使用者平均請求等待時間=concurrency * timetaken * 1000 / done
參考Jmeter、LR中的平均響應時間
Time per request: 10.336 [ms] (mean, across all concurrent requests)
————伺服器處理每個請求平均響應時間=timetaken * 1000 / done
Transfer rate: 82.39 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 75 16.1 74 121
Processing: 10 23 12.7 19 63
Waiting: 10 21 10.8 18 54
Total: 62 99 18.5 97 168
//網路連線情況
Percentage of the requests served within a certain time (ms)
50% 97
66% 104
75% 107
80% 110
90% 126
95% 138
98% 148
99% 168
100% 168 (longest request)
//整體響應時間的分佈比

二、Win環境下:
下載地址:https://www.apachelounge.com/download/
1、ab測試http請求
2、abs測試https請求
abs.exe -n 500 -c 100 -p C:\Users\Desktop\ab\cc.txt -T 'application/x-www-form-urlencoded' "https://xxx/mobileHandler.do"

引數:-n是次數,-c是併發數,-p是引數路徑,url是""雙引號
post請求: -T application/x-www-form-urlencoded
具體引數意義參考官網


預設是text/plan,需要根據實際情況自己指定

原文:https://blog.csdn.net/wx19900503/article/details/56847264