Mac/Linux 安裝ab(Apache Benchmark)

Mac安裝Apache Benchmark()

1.下載依賴

wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz  
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz  
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip 

安裝apr

1.tar -zxvf apr-1.4.5.tar.gz
2.cd  apr-1.4.5  
3../configure --prefix=/usr/local/apr  
4.make && make install  

安裝apr-util

1.tar -zxf apr-util-1.3.12.tar.gz  
2.cd apr-util-1.3.12  
3../configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config  
4.make && make install 

安裝pcre

1.unzip -o pcre-8.10.zip  
2.cd pcre-8.10  
3../configure --prefix=/usr/local/pcre  
4.make && make install  

2.安裝ab(Apache Benchmark)

下載

下載地址

安裝

1.tar -zxvf 安裝包
2../configure --prefix=/usr/local/apache2 --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre  
3.make && make install

安裝三個依賴可以解決configure: error: APR not found . Please read the documentation;configure: error: APR-util not found . Please read the documentation;configure: error: PCRE not found . Please read the documentation等問題

3.ab使用和參數詳解


ab -n1000 -c10 http://www..com/

c concurrency 請求併發數,默認爲1-n requests 請求總數;

-A auth-username:password 向服務器提供基本認證信息。用戶名和密碼之間有一個“:”隔開,並將以base64編碼形式發送,無論服務器是否需要(即是否發送了401認證需求代碼),此字符串都會被髮送。

-b windowsize Size of TCP send/receive buffer, in bytes.

-B local-address Address to bind to when making outgoing connections

-C cookie-name=value 對請求附加一個“Cookie:”頭行。其典型形式是:name=value的一個參數對。此參數可以重複。

-d 不顯示“percentage served within XX[ms] table”消息(爲以前版本提供支持)

-e csv-file 產生一個逗號分隔(CSV)文件,其中包含了處理每個相應百分比請求(從1%100%)所需要的相應百分比時間(以微妙爲單位)。由於這種格式已經“二進制化”。所以比“gnuplot”格式更有用。

-f protocol 指定SSL/TLS procotol()

-g gnuplot-file 把所有測試結果寫入一個“gnuplot”或者TSV(以TAB分隔)文件。此文件可以方便地導入Gnuplot,IDL,Mathematica,Excel中。其中的第一行爲標題。

-h 顯示使用方法的幫助信息

-H custom-header 對請求附加額外的頭信息,此參數的典型形式是一個有效的頭信息行,其中包含了以冒號分隔的字段和值(如:”Accept-Encoding:zip/zop;8bit“).

-i 執行HEAD請求,而不是GET請求

-k 啓用Keepalive功能,即在一個HTTP會話中執行多個請求。默認不啓用此功能

-p POST-file 包含了POST數據的文件

-P proxy-auth-username:password 對一箇中轉代理提供基本認證信息。用戶名和密碼用”:“隔開,並將以base64編碼形式發送。無論服務器是否需要(即是否發送了407代理認證需求代碼)此字符串都會被髮送。

-q 如果代理的請求數大於150,ab每處理大約10%或者100個請求時,會在stderr輸出一個進度計數、此-q標記可以屏蔽這些信息。

-r 在socket接收錯誤時不退出

-s 用於編譯中使用了SSL的受保護的https,而不是http協議的時候。此功能是實驗性的,最好不要用。

-S 不顯示中值和標準偏差值,而且在均值和中值爲標準偏差值得1-2倍時,也不顯示警告和出錯信息。默認時,會顯示最小值/均值/最大值等數值

-t timelimit 測試所進行的最大秒數。內部隱含值是”-n 50000“。它可以時對服務器的測試限制在一個固定的總時間以內。默認時:沒有時間限制。

-T content-type POST數據時所使用的”Content-type“頭信息

-u PUT-file File containing data to PUT. Remember to also set -T

-v verbosity 設置顯示信息的詳細程度,4或更大值會顯示頭信息,3或更大值可以顯示響應代碼(404200等),2或更大值可以顯示警告和其他信息。

-V 顯示版本號並退出

-w 以HTML表格信息輸出結果,默認時,它是白色背景的兩列寬度的一張表

-x <table>-attributes 設置<table>屬性的字符串。此屬性被填入<table 這裏>

-X proxy[:port] 對請求使用代理服務器

-y <tr>-attributes 設置<tr>屬性的字符串

-z <td>-attributes 設置<td>屬性的字符串

-Z ciphersuite 指定SSL/TLS密碼套件(見openssl密碼)

3.返回值分析
C:\Users\one_t>ab -n20 -c20 http://www.baidu.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 www.baidu.com (be patient).....done
 
 
 
 
 
Server Software:        BWS/1.1 //服務器版本
 
Server Hostname:        www.baidu.com   //服務器地址
 
Server Port:            80//服務器端口
 
Document Path:          /       //子路徑
 
Document Length:        118311 bytes     //傳輸數據大小
 
 
 
Concurrency Level:      20        //請求併發量
 
Time taken for tests:   3.966 seconds    //持續時間
 
Complete requests:      20        //總請求數
 
Failed requests:        19        //失敗的請求
 
   (Connect: 0, Receive: 0, Length: 19, Exceptions: 0)
 
Total transferred:      2384271 bytes    //總傳輸量
 
HTML transferred:       2365331 bytes    //響應正文傳輸量,減去了Total transferred中HTTP響應數據中的頭信息的長度
 
Requests per second:    5.04 [#/sec] (mean)    
 
//吞吐率,每秒請求數(相當於LR中的每秒事務數TPS),mean表示爲平均值:526.29/sec。計算公式:Complete requests / Time taken for tests
 
Time per request:       3966.402 [ms] (mean)
 
//請求所消耗的總時間,計算公式:Time token for tests/(Complete requests/Concurrency Level)
 
Time per request:       198.320 [ms] (mean, across all concurrent requests)    //平均請求時間
 
Transfer rate:          587.03 [Kbytes/sec] received    //表示這些請求在單位時間內從服務器獲取的數據長度,計算公式:Total trnasferred/ Time taken for tests
 
 
 
Connection Times (ms)    //消耗時間分解
 
              min  mean[+/-sd] median   max
 
Connect:        8   11   2.1     10      17
 
Processing:  1086 2207 699.3   2028    3845
 
Waiting:       12  410 290.8    339    1104
 
Total:       1096 2218 699.2   2038    3856
 
 
 
Percentage of the requests served within a certain time (ms)    //響應時間正態分佈
 
  50%   2233
 
  66%   4566
 
  75%   5678
 
  80%   7890
 
  90%   8901
 
  95%   9022
 
  98%   10333
 
  99%   13234
 
100%   15432 (longest request)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章