提高Apache效能的幾個方法
////////////////////////////////////
.KeepAlive On
讓同一個TCP連線狀態來提供一個以上的服務要求,當網頁有很多圖片時,可讓網站效能提高。
.MaxKeepAliveRequest 0
限制每次連線要求服務的上限,0表示無限制,數字越大效能越高。
.KeepAliveTimeout 15
在持續的連接中,Apache等待服務要求的時間。
.MinSpareServers 15
This is the minimum number of spare servers you want running at any given time. This way, if multiple simultaneous requests are received there will already be child processes running to handle them. Setting this number too high is a waste of system resources and setting it too low will cause the system to slow down.
.MaxSpareServers 65
.StartServers 15
預先啟動的伺服器行程數量,當常駐Apache行程被啟動時,有15個行程將開始跑起來,準備好來提供服務。
15 spare servers will run up to the maximum of 64.
.MaxClients 150
同時可允許啟動的行程數量,如果有超過150位的同時連線,則應該提高這個上限。
I think 500 is about right for most people's needs.
.MaxRequestPerChild 10000
為了讓記憶體緩衝能夠更新,則要限制每一個伺服器行程所能提供的要求服務,當提供10000次要求後,這個行程就會被Kill。
Sets the maximum number of requests each child process will handle. This is mostly to prevent memory leaks and other mishaps but is important nonetheless. Setting this too low will cause a large portion of child processes to end for no real reason, thus slowing down the site. This could be set to 0 (unlimited) but that would negate any protection from valid issues like memory leaks.
.HostnameLookups Off
用使用者端的IP位址去名稱伺服器DNS查詢主機名稱,為避免浪費網路資源,請關閉,除非要作網站資源使用的統計分析,才會打開此指令。
//////////////////////////////////////////////////////
At least when you are running Apache as your webserver on top of a FreeBSD box, you have a lot of possibilities to tune your system in order to achieve more performance.
Like on most operating systems the TCP/IP listen queue is often the first limit hit. It restricts the pending TCP requests. The second important parameter is the number of mbuf clusters which could be increased. Additionally you can increase the maximum number of allowed child processes and open file descriptors. So, for a heavily loaded machine increase these values in your kernel config via:
maxusers 256
options SOMAXCONN=256
options NMBCLUSTERS=4096
options CHILD_MAX=512
options OPEN_MAX=512
Additionally you can try to use maximum optimization when building the kernel itself by using the GCC compiler flags
-mpentium -O2 -fexpensive-optimizations -fomit-frame-pointer
or even try to compile the kernel with the latest EGCS-based Pentium-GCC variant. But please be carefully here, always keep a working kernel at hand when doing such optimization tests.
After tuning your operating system you can try to enhance the performance of Apache. In addition to the above kernel parameters you now first can increase the corresponding Apache parameters when building:
-DHARD_SERVER_LIMIT=256
-DDYNAMIC_MODULE_LIMIT=0
-DBUFFERED_LOGS
And then you can tune the Apache configuration accordingly:
MinSpareServers 256
StartServers 256
MaxSpareServers 256
MaxClients 256
Additionally you can increase Apaches performance again by tuning some more parameters:
MaxRequestsPerChild 10000
KeepAlive on
KeepAliveTimeout 15
MaxKeepAliveRequests 64
Timeout 400
IdentityCheck off
HostnameLookups off
<Files ~ "\.(html|cgi)$>
HostnameLookups on
</Files>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>