PS:前段時間配置php-fpm的時候,無意中發現原來它還有兩種進程管理方式。與Apache類似,它的進程數也是可以根據設置分為動態和靜態的。
php-fpm目前主要又兩個分支,分別對應于php-5.2.x的版本和php-5.3.x的版本。在5.2.x的版本中,php-fpm.conf使用的是xml格式,而在新的5.3.x版本中,則是和php.ini一樣的配置風格。
在5.2.x版本中,php-fpm.conf中對于進程管理號稱是有兩種風格,一種是靜態(static)的,一種是類似于apache風格(apache-like)的。
代碼如下:
Process manager settings
<value name=”pm”>
Sets style of controling worker process count.
Valid values are 'static' and ‘apache-like'
<value name=”style”>static</value>
按照文檔的說明,如果pm的style采用apache-like,啟動的進程數應該是和StartServers指定的一樣。不過經過數次的嘗試,會發現,實際上在這里將pm的style配置成apache-like沒有起任何作用。也就是說,這里的apache-like并沒有被實現。
不過,在最新的5.3.x的配套php-fpm中,apache風格的進程管理已經被實現了。
代碼如下:
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives:
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; Note: This value is mandatory.
;pm = dynamic
pm = static
由上面一段文字可知,對于進程的管理存在兩種風格——static和dynamic。和之前的版本的進程管理其實還是一樣的,只是將apache-like改成了dynamic,這樣更容易理解。
如果設置成static,php-fpm進程數自始至終都是pm.max_children指定的數量,不再增加或減少。
如果設置成dynamic,則php-fpm進程數是動態的,最開始是pm.start_servers指定的數量,如果請求較多,則會自動增加,保證空閑的進程數不小于pm.min_spare_servers,如果進程數較多,也會進行相應清理,保證多余的進程數不多于pm.max_spare_servers。
這兩種不同的進程管理方式,可以根據服務器的實際需求來進行調整。
這里先說一下涉及到這個的幾個參數,他們分別是pm、pm.max_children、pm.start_servers、pm.min_spare_servers和pm.max_spare_servers。
新聞熱點
疑難解答