apache配置最佳化測試apache配置最佳化測試
一、apache安裝
1、先解壓縮tar檔案
複製內容到剪貼簿
代碼:
tar -zxvf httpd-2.0.58.tar.gz
./configure --prefix=/usr/local/apache2test --enable-so --enable-shared=max --with-mpm=worker\
--enable-deflate --enable-headers --enable-rewrite --enable-proxy --enable-proxy --enable-ssl \
--with-ssl=/path/to/install/openssl_0.97i --enable-modules=all
&& make && make install
註:這是正式伺服器上的apache2的編譯參數,其中--with-mpm=worker --with-ssl=/path/to/install/openssl_0.97i
可以根據實際情況做出修改。
2、安裝php,並且在/usr/local/apache2test/conf目錄下的httpd.conf裡面的DSO支援之後加入
AddType application/x-httpd-php .php .phtml .html .htm
AddType application/x-httpd-php-source .phps
最後將測試的php網頁檔案添加到/usr/local/apache2test/htdocs目錄下。
3、測試載入器說明以及安裝
1)、ab是Apache超文字傳輸通訊協定 (HTTP)(HTTP)的效能測試工具。 其設計意圖是描繪當前所安裝的Apache的執行效能,主要是顯示
你安裝的Apache每秒可以處理多少個請求;
概要:運行/usr/local/apache-install-path/bin/ab -help查看ab的具體命令選項;
命令選項-c concurrency 一次產生的請求個數。預設是一次一個。
-n requests 在測試會話中所執行的請求個數。 預設時,僅執行一個請求,但通常其結果不具有代表意義
運行結果:主要要注意的是以下內容
Time taken for tests: 總共執行所花費的時間.(以上 1000 次共多久)
Requests per second: 每秒平均可以處理多少個connection.
備忘:每次僅僅能針對一個串連做重複的測試。
2)、Siege是一個壓力測試和評測工具,設計用於WEB開發這評估應用在壓力下的承受能力:可以根據配置對一個WEB網站
進行多使用者的並發訪問,記錄每個使用者所有請求過程的相應時間,並在一定數量的並發訪問下重複進行。
下載/安裝
Siege時一個開放原始碼項目,可以在http://www.google.com上尋找
備忘:最好選擇2.5以上版本,因為高版本多包括一個協助工具輔助,能夠做增量壓力測試,低版本不包括此工具。
安裝:
%./configure --prefix=/path/to/install && make && make install
siege使用說明:
在/path/to/install/bin/目錄下建立需要測試的連結檔案,如www.test.com.url,添加需要的測試的連結
http://10.5.3.122/test/google.php/
http://10.5.3.122/test/baidu.php/
http://10.5.3.122/test/sogou.php/
然後儲存。
siege使用範例:
siege -c 20 -r 2 -f www.chedong.com.url
參數說明:
-c 20 並發20個使用者
-r 2 重複迴圈2次
-f www.test.com.url 工作清單:URL列表
複製內容到剪貼簿
代碼:
輸出範例:
** Siege 2.59
** Preparing 20 concurrent users for battle. 這次“戰鬥”準備了20個並發使用者
The server is now under siege.. done. 服務在“圍攻”測試中:
Transactions: 40 hits 完成40次處理
Availability: 100.00 % 成功率
Elapsed time: 7.67 secs 總共用時
Data transferred: 877340 bytes 共資料轉送:877340位元組
Response time: 1.65 secs 相應用時1.65秒:顯示網路連接的速度
Transaction rate: 5.22 trans/sec 平均每秒完成5.22次處理:表示伺服器幕後處理的速度
Throughput: 114385.92 bytes/sec 平均每秒傳送資料:114385.92位元組
Concurrency: 8.59 最高並發數 8.59
Successful transactions: 40 成功處理次數
Failed transactions: 0 失敗處理次數
bombardment使用範例:
bombardment www.test.com.url 5 3 4 1
初始化URL列表:www.test.com.url
初始化為:5個使用者
每次增加:3個使用者
運行:4次
每個用戶端之間的延遲為:1秒
輸出範例和siege一致,但是會在每一次增量結束之後都有輸出。
4、測試方法說明
測試步驟:
方法1.安裝apache2後,直接使用apache2的預設設定配置,不做任何修改,進行測試;
方法2.按照以前文檔提出的Web容量規劃和記憶體的大小,計算出相應的啟動進程數,配置httpd.conf檔案,再進行測試;
複製內容到剪貼簿
代碼:
ServerLimit 400
StartServers 20
MinSpareServers 20
MaxSpareServers 50
MaxClients 300
MaxRequestsPerChild 10000
方法3.超過極限設定,進行測試。(規劃容量的2倍進行)
複製內容到剪貼簿
代碼:
1000個連結,分為不同的並發數請求,10、50、100、200、300、500
ab測試:
/usr/local/apache2.53/bin/ab -n 1000 -c 10 http://10.5.3.122/test/google.php/
/usr/local/apache2.53/bin/ab -n 1000 -c 50 http://10.5.3.122/test/google.php/
/usr/local/apache2.53/bin/ab -n 1000 -c 100 http://10.5.3.122/test/google.php/
/usr/local/apache2.53/bin/ab -n 1000 -c 200 http://10.5.3.122/test/google.php/
/usr/local/apache2.53/bin/ab -n 1000 -c 300 http://10.5.3.122/test/google.php/
/usr/local/apache2.53/bin/ab -n 1000 -c 500 http://10.5.3.122/test/google.php/
siege測試:
/usr/local/siege/bin/siege -c 10 -r 100 -f www.test.com.url
/usr/local/siege/bin/siege -c 50 -r 20 -f www.test.com.url
/usr/local/siege/bin/siege -c 100 -r 10 -f www.test.com.url
/usr/local/siege/bin/siege -c 200 -r 5 -f www.test.com.url
/usr/local/siege/bin/siege -c 300 -r 3 -f www.test.com.url
/usr/local/siege/bin/siege -c 500 -r 2 -f www.test.com.url
增量測試:
/usr/local/siege/bin/bombardment www.test.com.url 1 100 5 1
/usr/local/siege/bin/bombardment www.test.com.url 1 100 6 1
5、測試結果總結
ab測試:測試並發串連數在50~500的情況下,方法2比方法1效能略有提升,但是相差在10個並發串連數左右, 並且方法1方法2在測試並發數100的情況下,實際並發數都相差無幾。
siege測試:測試並發數從50之後直到500,效能都有提升,並且在測試並發數100、200、500的情況下,提升相差10~30個實際並發數。
bombardment測試:相差不大。
本次測試的結果不太理想,效能的變化不顯著,也不明顯,可以所屬於失敗的測試結果。
分析原因:
1.本身硬體設定不高,所以預設設定和修改後的設定變化不明顯,對效能的提升也明顯不足;
2.負載情況太少,由於系統效能原因,增量測試都不能過大的進行,系統效能load average過高;
3.測試頁面程式也太少,沒有太大說服力。