Linux Apache 2 性能測試,MaxClients 20000優化
為了客觀的瞭解Apache的服務器性能,在此選取Apache自帶的性能測試軟件ApacheBench, Version 2.0.40-dev and Version 2.3 分別作為性能測試工具。
1.比較現有T2000 Apache2.2.8經過優化前後的效果
Webserver IP:10.56.234.31
優化前httpd.conf:
----------------------------------------------------------------------
StartServers 10
MinSpareServers 50
MaxSpareServers 100
ServerLimit 10000
MaxClients 10000
MaxRequestsPerChild 0
----------------------------------------------------------------------
優化後httpd.conf:
----------------------------------------------------------------------
StartServers 150
MinSpareServers 10
MaxSpareServers 20
ServerLimit 20000
MaxClients 20000
MaxRequestsPerChild 10000
----------------------------------------------------------------------
測試命令: /opt/apache2.2.8/bin/ab -n 10000 -c 1000
http://127.0.0.1/pete/20kb/automot.jpg
測試方法: 訪問20kb的jpg圖片來獲取tps數據,為了排除網絡因素,選取127.0.0.1本地環路地址。
測試結果:
----------------------------------------------
使用ApacheBench v2.0進行測試
apache2.2.8(20k) 優化前 1657tps
apache2.2.8(20k) 優化後 1666tps
---------------------------------------------
使用 ApacheBench v2.3進行測試
apache2.2.8(20k) 優化前 1765tps
apache2.2.8(20k) 優化後 1822tps
-----------------------------------------------
測試結論:由於這個Apache2.2.8版本沒有編入worker.c模塊,無法進行worker優化。但是,單獨就對prefork的優化,發現性能提升很小。基本保持以後的水平。同時我們發現,測試結果受到T2000機器狀態影響很大。所以,本測試基本在沒有其他壓力的情況下進行。
2.比較現有T2000上Apache2.2.8和Apache2.2.11優化後的性能
Webserver IP:10.56.234.31
配置:
a. Apache2.2.8優化後配置請見step1
b.Apache2.2.11中對於httpd-mpm.conf優化:
----------------------------------------------------------------------
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
StartServers 150
MinSpareServers 10
MaxSpareServers 20
ServerLimit 20000
MaxClients 20000
MaxRequestsPerChild 10000
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
StartServers 2
MaxClients 1500
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
同時在httpd.conf中打開httpd-mpm.conf註釋。在編譯Apache2.2.11的worker模塊時修改了worker源代碼,
# vi server/mpm/worker/worker.c
找到下面幾行,並改成如下的數值,其目的是在源碼中修改apache可支持的最大線程數和最大客戶端數目。
# define DEFAULT_SERVER_LIMIT 256
# define MAX_SERVER_LIMIT 40000
# define DEFAULT_THREAD_LIMIT 256
# define MAX_THREAD_LIMIT 40000
----------------------------------------------------------------------
測試命令:
/opt/apache2.2.8/bin/ab -n 10000 -c 1000
http://127.0.0.1/automot.jpg
/opt/apache2.2.8/bin/ab -n 10000 -c 1000
http://127.0.0.1/pete/20kb/automot.jpg
/opt/apache2.2.11/bin/ab -n 10000 -c 1000
http://127.0.0.1/automot.jpg
/opt/apache2.2.11/bin/ab -n 10000 -c 1000
http://127.0.0.1/pete/20kb/automot.jpg
測試方法: 訪問20kb的jpg圖片來獲取tps數據,為了排除網絡因素,選取127.0.0.1本地環路地址。
測試結果:
-----------------------------------------------
使用ApacheBench v2.0進行測試
apache2.2.8(20k) 1631tps
apache2.2.11(20k) 1581tps
-----------------------------------------------
----------------------------------------------
使用ApacheBench v2.3進行測試
apache2.2.8(20k) 1773tps
apache2.2.11(20k) 1747tps
----------------------------------------------
測試結論:
Apache2.2.8和Apache2.2.11經過優化後的測試結果相近。
3.比較CMCC的機遇HP Blade的Apache2.0.52的性能
Webserver IP:10.56.135.64
優化配置:同step2中Apache2.2.11配置
測試命令:
/opt/apache2.2.8/bin/ab -n 10000 -c 1000
http://10.56.135.64/automot.jpg
/usr/bin/ab -n 10000 -c 1000
http://10.56.135.64/automot.jpg
測試方法:訪問20kb的jpg圖片來獲取tps數據,為了排除網絡因素,選取127.0.0.1本地環路地址。
測試結果:
-----------------------------------------------
使用ApacheBench v2.0.1.141進行測試
Apache2.0.52(20k) 3773tps
-----------------------------------------------
----------------------------------------------
使用ApacheBench v2.0.1.146進行測試
Apache2.0.52(20k) 7556tps
----------------------------------------------
測試結論:測試工具的版本差異會造成結果的巨大差異。但是,總的來說,CMCC HP Blade webserver性能在此項測試中要優於T2000 Webserver。初步懷疑是硬件系統架構差異引起的性能差異。