標籤:php 參數配置
沒事查看了一下php日誌,發現提示進程數不夠,日誌資訊如下:
[04-Nov-2014 14:19:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 15 total children
[04-Nov-2014 14:29:27] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 16 total children
[04-Nov-2014 16:51:04] NOTICE: Finishing ...
[04-Nov-2014 16:51:04] NOTICE: exiting, bye-bye!
[04-Nov-2014 16:51:06] NOTICE: fpm is running, pid 31023
[04-Nov-2014 16:51:06] NOTICE: ready to handle connections
[04-Nov-2014 19:01:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 17 total children
[04-Nov-2014 19:54:47] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 17 total children
[04-Nov-2014 20:36:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 19 total children
[04-Nov-2014 21:18:56] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 17 total children
[05-Nov-2014 05:30:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 15 total children
[05-Nov-2014 11:01:37] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 8 children, there are 0 idle, and 17 total children
[05-Nov-2014 11:01:38] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve
rs), spawning 16 children, there are 0 idle, and 21 total children
使用下面的命令查看php進程:
[[email protected] ~]# ps -ef |grep php
root 25874 20907 0 11:56 pts/0 00:00:00 more index.php
www 26030 31023 32 12:02 ? 00:00:26 php-fpm: pool www
www 26037 31023 31 12:02 ? 00:00:22 php-fpm: pool www
www 26042 31023 31 12:02 ? 00:00:20 php-fpm: pool www
www 26046 31023 30 12:02 ? 00:00:17 php-fpm: pool www
www 26054 31023 30 12:02 ? 00:00:15 php-fpm: pool www
www 26059 31023 30 12:02 ? 00:00:14 php-fpm: pool www
www 26062 31023 30 12:03 ? 00:00:12 php-fpm: pool www
www 26063 31023 30 12:03 ? 00:00:09 php-fpm: pool www
www 26066 31023 30 12:03 ? 00:00:09 php-fpm: pool www
www 26089 31023 23 12:03 ? 00:00:02 php-fpm: pool www
www 26092 31023 24 12:03 ? 00:00:01 php-fpm: pool www
root 26097 25911 0 12:03 pts/1 00:00:00 grep php
root 31023 1 0 Nov04 ? 00:00:09 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
記憶體佔用情況:只用了2G左右的記憶體
[[email protected] etc]# free -m
total used free shared buffers cached
Mem: 19990 19685 304 0 256 16949
-/+ buffers/cache: 2480 17509
Swap: 19999 112 19887
開啟設定檔php-fpm.conf發現:pm.max_children = 5
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/CA/wKiom1RZ1u3SDyFKAAFuqjFfjAA932.jpg" title="QQ圖片20141105155054.jpg" alt="wKiom1RZ1u3SDyFKAAFuqjFfjAA932.jpg" />
修改成如下參數後,發現php日誌中無此警示了:
; Note: This value is mandatory.
pm.max_children = 1024
; 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 = 512
; 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 = 4
; 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 = 512
查看php-fpm的子進程數,跟設定檔裡面設定的一樣,等於pm.start_servers+pm.min_spare_servers
[[email protected] etc]# ps -ef |grep php |wc -l
515
修改php設定檔後,記憶體佔用從2G變成了6.8G左右,增長了4.8G左右,一個php進程開銷佔到了8M左右,這個可以根據實際的記憶體情況來進行修改。
[[email protected] log]# free -m
total used free shared buffers cached
Mem: 19990 19438 551 0 189 12414
-/+ buffers/cache: 6835 13154
Swap: 19999 129 19870
補充:
php-fpm有一個參數 max_requests,該參數指明了,每個children最多處理多少個請求後便會被關閉,預設的設定是500。因為php是把請求輪詢給每個children,在大流量下,每個childre到達max_requests所用的時間都差不多,這樣就造成所有的children基本上在同一時間被關閉,這樣會導致此時nginx發給php的請求無法得到相應,會出現短時間的502.解決方案:
增加children的數量,並且將 max_requests 設定未 0 或者一個比較大的值
一般增加max_requests到102400,可能有效果。
本文出自 “營運之道” 部落格,謝絕轉載!
關於php配置參數