linux中php-fpm服務掛掉問題排除方法

來源:互聯網
上載者:User

今天發了個連結,可能同時線上的人瞬間比較多,結果網站報503錯誤,回去開啟php-fpm錯誤記錄檔一看,php-fpm服務掛掉了,報如下錯誤:

[04-Apr-2016 15:38:04] NOTICE: systemd monitor interval set to 10000ms
[05-Apr-2016 19:03:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 29 total children
[05-Apr-2016 19:03:09] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 34 total children
[05-Apr-2016 19:03:11] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 39 total children
[05-Apr-2016 19:03:12] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 44 total children
[05-Apr-2016 19:03:13] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 49 total children
[05-Apr-2016 19:03:14] WARNING: [pool www] server reached pm.max_children setting (50), consider raising it

錯誤提示建議增加pm.start_servers數量,開啟我的php-fpm配置:

pm.max_children = 50
 
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 15
 
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5
 
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35

這裡pm.start_servers之前我設定為5,注意設定檔也說明start_servers的值預設是max_spare_servers-min_spare_servers的一半。(ps:具體的值要根據伺服器配置情況和壓力測試得出)

網站伺服器是阿里雲1G頻寬,1G記憶體,1核CPU配置,關鍵還在一台機子上裝了資料庫,redis各種服務。

幾個php-fpm重要參數說明

Shell

1
pm.max_children = 24

static模式下建立的子進程數或dynamic模式下同一時刻允許最大的php-fpm子進程數量

pm.start_servers = 16

動態方式下的起始php-fpm進程數量


pm.min_spare_servers = 12

動態方式下伺服器空閑時最小php-fpm進程數量


pm.max_spare_servers = 24

動態方式下伺服器空閑時最大php-fpm進程數量

經驗人士的總結:

一般php-fpm進程佔用20~30m左右的記憶體就按30m算。如果單獨跑php-fpm,動態方式起始值可設定實體記憶體Mem/30M,由於大家一般Nginx、MySQL都在一台機器上,於是預留一半給它們,即php-fpm進程數為$Mem/2/30。
 調整之後的幾個值是:


pm = dynamic
pm.max_children = 50
pm.start_servers = 15
pm.min_spare_servers = 10
pm.max_spare_servers = 40

重啟php-fpm服務:service php70-php-fpm reload,繼續使用top命令查看記憶體使用量情況,發現十幾個php-fpm啟動。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.