溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PHP fpm優(yōu)化

發(fā)布時間:2020-10-08 08:21:18 來源:網(wǎng)絡 閱讀:4017 作者:lrm929 欄目:web開發(fā)

在優(yōu)化PHP的進程數(shù)的時候我們首先要了解我們服務器執(zhí)行一個php使用的內存

 1: 查詢一個php占用的內存方法

pmap $(pgrep php-fpm | head -1)

我這里查詢到的是

00002ba5d0bec000      4K rw-s-  /dev/zero (deleted)

00002ba5d0bed000      4K rw-s-  /dev/zero (deleted)

00007fffc568b000     80K rwx--    [ stack ]

00007fffc569f000      4K rw---    [ anon ]

00007fffc57fd000     12K r-x--    [ anon ]

ffffffffff600000   8192K -----    [ anon ]

 total           309548K

大概30MB的樣子

我本身機器內存是32G,那么理論上計算最大能承受php的并發(fā)是 32G/30MB=1092個

那么如果除去系統(tǒng)跟其他軟件的使用內存大概算900個

2 :php-fpm的配置公式:pm.start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2

pm.max_children的計算方法,本機內存/30兆每個為最大的限定值再適當減小
相關參數(shù)解讀:
pm.max_children:靜態(tài)方式下開啟的php-fpm進程數(shù)量。
pm.start_servers:動態(tài)方式下的起始php-fpm進程數(shù)量。
pm.min_spare_servers:動態(tài)方式下的最小php-fpm進程數(shù)量。
pm.max_spare_servers:動態(tài)方式下的最大php-fpm進程數(shù)量。
針對我的服務器情況調整這幾個值為(當然我這邊是集群所以我啟動300個已經(jīng)足夠了):
pm.max_children = 300
pm.start_servers = 155
pm.min_spare_servers = 10
pm.max_spare_servers = 300

###################################################

(備注:如果不按這個公式計算做配置多多少少會出現(xiàn)寫問題,比如

  seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 34 total children    (這個很明顯是要你調節(jié)進程數(shù))

  child 1616 exited with code 0 after 619688.718148 seconds from start  (一下三個好像都是提示執(zhí)行超時)

  child 14636 exited on signal 15 (SIGTERM) after 269249.100189 seconds from star 

  request: "POST /test.php") execution timed out (198.776247 sec), terminating

   等等類似的報錯

   如果是ngixn做的前端代理會出現(xiàn)當后端服務器出現(xiàn)類似問題就會連接失敗提示沒在線的主機等等情況

     no live upstreams while connecting to upstream, client

####################################################



向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI