web壓力測試工具ab安裝及使用

​## 安裝nginx

brew install apr

brew install apr-util

brew install openssl --upgrade

wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.gz

tar zxvf httpd-2.4.33.tar.gz 

cd httpd-2.4.33

./configure --with-apr=/usr/local/opt/apr --with-apr-util=/usr/local/opt/apr-util --prefix=/usr/local/apache --with-ssl=/usr/local/opt/openssl --enable-ssl --enable-cgi --enable-rewrite  --with-zlib --with-pcre --with-mpm=prefork --enable-modules=most --enable-mpms-shared=all

sudo make 

sudo make install

測試

cd /usr/local/apache/bin/

ulimit -n 10000

./ab -V

./ab -n 1000 -c 1000 -t 1 https://www.xxx.com

結果

This is ApacheBench, Version 2.3 <Revision: 1826891 >

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking api.xxx.com (be patient)

Finished 355 requests

Server Software:        nginx                                   # 被測試的Web服務器軟件名稱

Server Hostname:        api.xxx.com                    # 請求的URL主機名

Server Port:            443                                     # 被測試的Web服務器軟件的監聽端口

SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256

TLS Server Name:        api.xxx.com

Document Path:          /news/index                             # 請求的URL中的根絕對路徑,經過該文件的後綴名,咱們通常能夠了解該請求的類型

Document Length:        0 bytes                                 # HTTP響應數據的正文長度

Concurrency Level:      1000                                    # 併發用戶數,這是咱們設置的參數之一

Time taken for tests:   1.007 seconds                           # 全部這些請求被處理完成所花費的總時間

Complete requests:      355                                     # 完成請求數

Failed requests:        0                                       # 失敗的請求數量,這裏的失敗是指請求在鏈接服務器、發送數據等環節發生異常,以及無響應後超時的狀況。若是接收到的HTTP響應數據的頭信息中含有2XX之外的狀態碼,則會在測試結果中顯示另外一個名爲       「Non-2xx responses」的統計項,用於統計這部分請求數,這些請求並不算在失敗的請求中。

Non-2xx responses:      380

Total transferred:      187720 bytes                            # 網絡總傳輸量 

HTML transferred:       0 bytes                                 # HTML內容傳輸量

Requests per second:    352.54 [#/sec] (mean)                   # 吞吐量-每秒請求數

Time per request:       2836.555 [ms] (mean)                    # 服務器收到請求,響應頁面要花費的時間 

Time per request:       2.837 [ms] (mean, across all concurrent requests) # 平均每秒網絡上的流量,能夠幫助排除是否存在網絡流量過大致使響應時間延長的問題

Transfer rate:          182.05 [Kbytes/sec] received

網絡上消耗的時間的分解:

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:       62  339 146.0    389     730

Processing:    36   77  21.0     77     131

Waiting:       19   75  20.2     77     121

Total:        123  416 156.4    477     817

整個場景中全部請求的響應狀況。在場景中每一個請求都有一個響應時間 

其中 50% 的用戶響應時間小於 473 毫秒 

80 % 的用戶響應時間小於 537 毫秒 

最大的響應時間小於 817 毫秒 

Percentage of the requests served within a certain time (ms)

  50%    473

  66%    511

  75%    519

  80%    537

  90%    580

  95%    607

  98%    782

  99%    805

 100%    817 (longest request)

結果分析

Server Software 表示被測試的Web服務器軟件名稱

Server Hostname 表示請求的URL主機名

Server Port 表示被測試的Web服務器軟件的監聽端口

Document Path 表示請求的URL中的根絕對路徑,經過該文件的後綴名,咱們通常能夠了解該請求的類型

Document Length 表示HTTP響應數據的正文長度

Concurrency Level 表示併發用戶數,這是咱們設置的參數之一

Time taken for tests 表示全部這些請求被處理完成所花費的總時間

Complete requests 表示總請求數量,這是咱們設置的參數之一

Failed requests 表示失敗的請求數量,這裏的失敗是指請求在鏈接服務器、發送數據等環節發生異常,以及無響應後超時的狀況。若是接收到的HTTP響應數據的頭信息中含有2XX之外的狀態碼,則會在測試結果中顯示另外一個名爲       「Non-2xx responses」的統計項,用於統計這部分請求數,這些請求並不算在失敗的請求中。

Total transferred 表示全部請求的響應數據長度總和,包括每一個HTTP響應數據的頭信息和正文數據的長度。注意這裏不包括HTTP請求數據的長度,僅僅爲web服務器流向用戶PC的應用層數據總長度。

HTML transferred 表示全部請求的響應數據中正文數據的總和,也就是減去了Total transferred中HTTP響應數據中的頭信息的長度。

Requests per second 吞吐率,計算公式:Complete requests / Time taken for tests

Time per request 用戶平均請求等待時間,計算公式:Time token for tests/(Complete requests/Concurrency Level)

Time per requet(across all concurrent request) 服務器平均請求等待時間,計算公式:Time taken for tests/Complete requests,正好是吞吐率的倒數。也能夠這麼統計:Time per request/Concurrency Level

Transfer rate 表示這些請求在單位時間內從服務器獲取的數據長度,計算公式:Total trnasferred/ Time taken for tests,這個統計很好的說明服務器的處理能力達到極限時,其出口寬帶的需求量。

Percentage of requests served within a certain time(ms) 這部分數據用於描述每一個請求處理時間的分佈狀況,好比以上測試,80%的請求處理時間都不超過6ms,這個處理時間是指前面的Time per request,即對於單個用戶而言,平均每一個請求的處理時間。

重點分析
Requests per second
Time per request
Percentage of requests served within a certain time(ms)web

參數說明

格式:ab optionshostname[:port]/path

-n requests Number of requests to perform

//在測試會話中所執行的請求個數(本次測試總共要訪問頁面的次數)。默認時,僅執行一個請求。

-c concurrency Number of multiple requests to make

//一次產生的請求個數(併發數)。默認是一次一個。

-t timelimit Seconds to max. wait for responses

//測試所進行的最大秒數。其內部隱含值是-n 50000。它可使對服務器的測試限制在一個固定的總時間之內。默認時,沒有時間限制。

-p postfile File containing data to POST

//包含了須要POST的數據的文件,文件格式如「p1=1&p2=2」.使用方法是 -p 111.txt 。 (配合-T)

-T content-type Content-type header for POSTing

//POST數據所使用的Content-type頭信息,如 -T 「application/x-www-form-urlencoded」 。 (配合-p)

-v verbosity How much troubleshooting info to print

//設置顯示信息的詳細程度 – 4或更大值會顯示頭信息, 3或更大值能夠顯示響應代碼(404, 200等), 2或更大值能夠顯示警告和其餘信息。 -V 顯示版本號並退出。

-w Print out results in HTML tables

//以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。

-i Use HEAD instead of GET

// 執行HEAD請求,而不是GET。

-x attributes String to insert as table attributes

-y attributes String to insert as tr attributes

-z attributes String to insert as td or th attributes

-C attribute Add cookie, eg. -C 「c1=1234,c2=2,c3=3″ (repeatable)

//-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數能夠重複,用逗號分割。

提示:能夠藉助session實現原理傳遞 JSESSIONID參數, 實現保持會話的功能,如

-C 」 c1=1234,c2=2,c3=3, JSESSIONID=FF056CD16DA9D71CB131C1D56F0319F8″ 。

-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 attribute Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

//-P proxy-auth-username:password 對一箇中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。不管服務器是否須要(即, 是否發送了401認證需求代碼),此字符串都會被髮送。

-X proxy:port Proxyserver and port number to use

-V Print version number and exit

-k Use HTTP KeepAlive feature

-d Do not show percentiles served table.

-S Do not show confidence estimators and warnings.

-g filename Output collected data to gnuplot format file.

-e filename Output CSV file with percentages served

-h Display usage information (this message)

//-attributes 設置屬性的字符串. 缺陷程序中有各類靜態聲明的固定長度的緩衝區。另外,對命令行參數、服務器的響應頭和其餘外部輸入的解析也很簡單,這可能會有不良後果。它沒有完整地實現 HTTP/1.x; 僅接受某些’預想’的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即你多是在測試ab而不是服務器的性能。
相關文章
相關標籤/搜索