【ab測試】 從安裝到使用

安裝

yum -y install httpd-tools # centos,redhat
apt-get install apache2-utils   #ubuntu Debian 

測試

ab -n1000 -c 10 http:/www.taoquan.ink/ # -n訪問1000次, -c併發10個

參數:

//在測試會話中所執行的請求個數。默認時,僅執行一個請求
-n requests     Number of requests to perform
//一次產生的請求個數。默認是一次一個。
-c concurrency Number of multiple requests to make
//測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。
-t timelimit    Seconds to max. wait for responses
//包含了需要POST的數據的文件.
-p postfile     File containing data to POST
//POST數據所使用的Content-type頭信息。
-T content-type Content-type header for POSTing
//設置顯示信息的詳細程度 - 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號並退出。
-v verbosity    How much troubleshooting info to print
//以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。
-w              Print out results in HTML tables
// 執行HEAD請求,而不是GET。
-i              Use HEAD instead of GET
 
//-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重複。
-C attribute    Add cookie, eg. ‘Apache=1234. (repeatable)
//頭信息
-H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
Inserted after all normal header lines. (repeatable)
-A attribute    Add Basic WWW Authentication, the attributes
are a colon separated username and password.
//-P proxy-auth-username:password 對一箇中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被髮送。
-P attribute    Add Basic Proxy Authentication, the attributes
are a colon separated username and password.

常用

帶參數和頭的post

參數寫到文件,頭用-H

{"userId":"5621482","userKey":"","giftId":"0","amount":"0","autoRefining":"0"}
ab -n 1000 -c 10  -p "post2.txt" -T "application/json" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: d6xxs-sdf-sdf09d" -H "apiVersion:test" -H "phoneBrand:iPhone" -H "phoneSystem:iOS" -H "phoneModels:wgl-test" -H "appMarket:wgl-test" -H "appVersionCode:wgl-test" -H "appVersionName:wgl-test" "127.0.0.1:8668/user/action/test"

結果:

Server Software:        Apache          #服務器軟件
Server Hostname:        www.taoquan.ink #域名
Server Port:            80              #請求端口號
Document Path:          /               #文件路徑
Document Length:        40888 bytes     #頁面字節數
Concurrency Level:      10              #請求的併發數
Time taken for tests:   27.300 seconds  #總訪問時間
Complete requests:      1000            #請求成功數量
Failed requests:        0               #請求失敗數量
Write errors:           0
Total transferred:      41054242 bytes  #請求總數據大小(包括header頭信息)
HTML transferred:       40888000 bytes  #html頁面實際總字節數
Requests per second:    36.63 [#/sec] (mean)  #每秒多少請求,這個是非常重要的參數數值,服務器的吞吐量
Time per request:       272.998 [ms] (mean)     #用戶平均請求等待時間 
Time per request:       27.300 [ms] (mean, across all concurrent requests) # 服務器平均處理時間,也就是服務器吞吐量的倒數                  
Transfer rate:          1468.58 [Kbytes/sec] received  #每秒獲取的數據長度
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       43   47   2.4     47      53
Processing:   189  224  40.7    215     895
Waiting:      102  128  38.6    118     794
Total:        233  270  41.3    263     945

Percentage of the requests served within a certain time (ms)
  50%    263    #50%用戶請求在263ms內返回
  66%    271    #66%用戶請求在271ms內返回
  75%    279    #75%用戶請求在279ms內返回
  80%    285    #80%用戶請求在285ms內返回
  90%    303    #90%用戶請求在303ms內返回
  95%    320    #95%用戶請求在320ms內返回
  98%    341    #98%用戶請求在341ms內返回
  99%    373    #99%用戶請求在373ms內返回
 100%    945 (longest request)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章