最近發(fā)現(xiàn)自己是個干雜活兒的人,因此把本博的名字都改成了“不求甚解”,純粹都為了解決眼前的問題,這樣的工作方式已經(jīng)完完全全背離了自己的習慣。廢話少說,切入正題,最近對Apache中的一些參數(shù)做了些了解,下面就記錄一下我的理解。
- # worker MPM
- # ThreadLimit: maximum setting of ThreadsPerChild
- # ServerLimit: maximum setting of StartServers
- # 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
- <IfModule worker.c>
- ThreadLimit 125
- ServerLimit 320
- StartServers 5
- MaxClients 8000
- MinSpareThreads 125
- MaxSpareThreads 1250
- ThreadsPerChild 125
- MaxRequestsPerChild 1000
- </IfModule>
其中最重要的參數(shù)是
ThreadsPerChild和MaxClients:
- ##ThreadsPerChild 每個子進程建立的線程數(shù),子進程在啟動時建立這些線程后就不再建立新的線程了
- ##MaxClients 允許同時伺服的最大接入請求數(shù)量(在worker下就是最大線程數(shù)量)
-
- ##ServerLimit:對最大子進程數(shù)的上限,該值必須大于等于MaxClients/ThreadsPerChild
- ##ThreadLimit:對ThreadsPerChild的上限,該值必須大于等于 ThreadsPerChild,如果將ThreadLimit設(shè)置成一個高出實際需要很多的ThreadsPerChild值,將會有過多的共享內(nèi)存被 分配,應(yīng)當和ThreadsPerChild可能達到的最大值保持一致.
- ##StartServers:服務(wù)器啟動時的服務(wù)進程數(shù)目,該值肯定小于等于ServerLimit
- ##MinSpareThreads和MaxSpareThreads:通過新建或結(jié)束子進程的方式,將空閑線程的總數(shù)維持在這個范圍內(nèi)
- ##MaxRequestsPerChild:用于控制服務(wù)器建立新進程和結(jié)束舊進程的頻 率,其實是一個為了防止內(nèi)存溢出的參數(shù),每個子進程在其生存期內(nèi)允許伺服的最大請求數(shù)量。到達MaxRequestsPerChild的限制后,子進程將 會結(jié)束。對于KeepAlive鏈接,只有第一個請求會被計數(shù)。事實上,它改變了每個子進程限制最大鏈接數(shù)量的行為。
可以通過檢查HTTPServer/logs/error_log日志,判斷MaxClients是否需要增加,如果有下面的報錯,就說明apache自上次重啟至今,曾經(jīng)發(fā)生過達到MaxClients的情況:
-
- Tue Jun 07 16:36:03 2011] [error] server reached MaxClients setting, consider raising the MaxClients setting
需要注意的是,這樣的報錯并不會出現(xiàn)多次,當?shù)诙芜_到MaxClients時,error_log不會記錄。
還有一種可以實時看到連接數(shù)的方法,就是打開
server-status頁面,設(shè)置方法如下:
1. 去掉以下部分的注釋
- LoadModule status_module modules/mod_status.so
- <IfModule mod_status.c>
- ExtendedStatus On
- </IfModule>
2.修改以下部分
- <Location /server-status>
- SetHandler server-status
- # Order deny,allow
- # Deny from all
- Allow from all
- </Location>
重啟ihs
使用:http://yourhost/server-status 可以進入監(jiān)控頁面
如果瀏覽器支持刷新,可以http://your_host/server-status?refresh=5 以便每 5 秒鐘刷新一次
在打開的監(jiān)控頁面中:"." Open slot with no current process,這里面的單個進程的“.”的數(shù)量其實對應(yīng)與ThreadLimit這個值。
- <IfModule worker.c>
- ThreadLimit 10
- ServerLimit 2
- StartServers 1
- MaxClients 2
- MinSpareThreads 1
- MaxSpareThreads 2
- ThreadsPerChild 1
- MaxRequestsPerChild 1
- </IfModule>
httpd.conf的MPM配置如上例,在監(jiān)控頁面中的輸出如下,其中有2個進程,各10個ThreadLimit,但由于ThreadsPerChild的限制,其實很多.是沒有用的。
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。