PHP fpm優化【轉】

在優化PHP的進程數的時候咱們首先要了解咱們服務器執行一個php使用的內存php

 1: 查詢一個php佔用的內存方法前端

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

我這裏查詢到的是服務器

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

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

00007fffc568b000     80K rwx--    [ stack ]優化

00007fffc569f000      4K rw---    [ anon ]spa

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

ffffffffff600000   8192K -----    [ anon ]code

 total           309548K

大概30MB的樣子

我自己機器內存是32G,那麼理論上計算最大能承受php的併發是 32G/30MB=1092個

那麼若是除去系統跟其餘軟件的使用內存大概算900個

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

pm.max_children的計算方法,本機內存/30兆每一個爲最大的限定值再適當減少
相關參數解讀:
pm.max_children:靜態方式下開啓的php-fpm進程數量。
pm.start_servers:動態方式下的起始php-fpm進程數量。
pm.min_spare_servers:動態方式下的最小php-fpm進程數量。
pm.max_spare_servers:動態方式下的最大php-fpm進程數量。
針對個人服務器狀況調整這幾個值爲(固然我這邊是集羣因此我啓動300個已經足夠了):
pm.max_children = 300
pm.start_servers = 155
pm.min_spare_servers = 10
pm.max_spare_servers = 300

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

(備註:若是不按這個公式計算作配置多多少少會出現寫問題,好比

  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    (這個很明顯是要你調節進程數)

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

  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作的前端代理會出現當後端服務器出現相似問題就會鏈接失敗提示沒在線的主機等等狀況

     no live upstreams while connecting to upstream, client

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

轉自

PHP fpm優化 - 信不信由你 - 51CTO技術博客http://312461613.blog.51cto.com/965442/1559672/

相關文章
相關標籤/搜索