服務器負載太大而影響程序效率是很常見的,Apache服務器自帶有一個叫ab(ApacheBench)的工具,在bin目錄下。ab專門用于HTTP Server的benchmark testing,可以同時模擬多個并發請求,使用這個輕巧的工具我們可以對服務器進行負載測試。
今天在公司也用它作一些測試,現在整理了下它的一些東西分享下。
首先我們要得到Apache服務器的目錄下bin的路徑,我電腦中的路徑是D:/wamp/bin/apache/Apache2.2.21/bin,打開cmd,轉到這個目錄下,在其中輸入:ab -n 10 -c 10 //www.companysz.com/ 這條指令,這條指令的意思是:ab -n 全部請求數 -c 并發數 測試URL。這里值得注意的是,如果你的測試URL是一個網站的網址,請記得在其后加上/,否則會無法工作。
以下是我運行的結果:
代碼如下:
D:/wamp/bin/apache/Apache2.2.21/bin>ab -n 10 -c 10 //www.companysz.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.companysz.com (be patient)…..done
Server Software: Microsoft-IIS/6.0 //Microsoft-IIS服務器版本6.0
Server Hostname: www.companysz.com //服務器主機名
Server Port: 80 //服務器端口
Document Path: / //測試的頁面文檔
Document Length: 32639 bytes //文檔大小
Concurrency Level: 10 //并發數
Time taken for tests: 13.548 seconds //整個測試持續的時間
Complete requests: 10 //完成的請求數量
Failed requests: 0 //失敗的請求數量
Write errors: 0
Total transferred: 331070 bytes //整個場景中的網絡傳輸量
HTML transferred: 326390 bytes //整個場景中的HTML內容傳輸量
Requests per second: 0.74 [#/sec] (mean) //每秒事務數 ,后面括號中的 mean 表示這是一個平均值
Time per request: 13547.775 [ms] (mean) //平均事務響應時間 ,后面括號中的 mean 表示這是一個平均值
Time per request: 1354.777 [ms] (mean, across all concurrent requests) //每個請求實際運行時間的平均值
Transfer rate: 23.86 [Kbytes/sec] received //平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題
新聞熱點
疑難解答