ab命令壓測
在效能調優中,ab命令和iperf命令比較好用的,下面就介紹一下ab命令
ApacheBench
ab是apacheBench的縮寫,是一個單執行緒命令,是Apache伺服器自帶的一個web壓力測試工具,最初是用於測試Apache HTTP Server。使用時,ab命令會建立併發訪問執行緒,模擬多個訪問者同時對某一個URL地址進行訪問。
使用的方法:
ab [option] [http://]host[:port]/path
例如:ab -n 100 -c 10 "http://en.wikipedia.org/wiki/Main_Page"
其中[option]是ab命令提供的可選引數,列舉一些常用的引數:
-n //requests Number of requests to perform 指定壓力測試總共訪問頁面的次數,預設是1
-c //concurrency Number of multiple requests to make at a time 用於一次產生請求的併發數,預設是1
-r //Don't exit on socket receive errors.指定接收到錯誤資訊時不退出程式。
-B //address Address to bind to when making outgoing connections 綁定出口IP地址
-t //timelimit Seconds to max. to spend on benchmarking This implies -n 50000 測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對伺服器的測試限制在一個固定的總時間以內。預設時,沒有時間限制。
-s //timeout Seconds to max. wait for each response Default is 30 seconds 每個相應的最長的時間,預設是30秒
-g //filename Output collected data to gnuplot format file 輸出結果資訊到gnuplot格式的檔案中。
-e //filename Output CSV file with percentages served 輸出結果資訊到CSV格式的檔案中。
-S // Do not show confidence estimators and warnings. 不顯示預估和警告資訊。
-d //Do not show percentiles served table. 不顯示百分比。
-k //Use HTTP KeepAlive feature 使用HTTP的KeepAlive特性。
-b //windowsize Size of TCP send/receive buffer, in bytes TCP的傳送/接受視窗,以位元組為單位
-p //postfile File containing data to POST 包含需要post的資料檔案,例如:-p a.txt,此外還需要結合-T,並且檔案的內容需類似像"key1=value1&key2=vaule2"形式
-T //content-type Content-type header for POSTing 設定Context-Type請求頭資訊,如-T “application/x-www-form-urlencoded”預設值為text/plain
-X //proxy:port Proxyserver and port number to use 指定使用的代理伺服器和埠號,例如:"126.10.10.3:88"
-v //verbosity How much troubleshooting info to print 設定列印幫助資訊的詳細程度,4或更大值會顯示頭資訊, 3或更大值可以顯示響應程式碼(404, 200等), 2或更大值可以顯示警告和其他資訊。
-w //Print out results in HTML tables 以HTML表的格式輸出結果。預設時,它是白色背景的兩列寬度的一張表。
-i //Use HEAD instead of GET 使用HEAD請求代替GET請求
-C //cookie-name=value 新增cookie資訊,其典型形式是name=value的一個引數對。此引數可以重複,用逗號分割。
-H //attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip' Inserted after all normal header lines. (repeatable) 新增任意的請求頭,例如:"Accept-Encoding: gzip",此引數可重複
-P // proxy-auth-username:password 對一箇中轉代理提供BASIC認證信任。使用者名稱和密碼用英文冒號隔開,並以base64編碼形式傳送。無論伺服器是否需要(即, 是否傳送了401認證需求程式碼),此字串都會被髮送。
-A //Add Basic WWW Authentication, the attributes are a colon separated username and password.基本網路認證,使用者名稱和密碼之間用英文冒號隔開。
-x //attributes String to insert as table attributes 插入字串作為table標籤的屬性。
-y //attributes String to insert as tr attributes 插入字串作為tr標籤的屬性。
-z //attributes String to insert as td or th attributes 插入字串作為td標籤的屬性。