wewe2 发表于 2014-11-6 09:16:42

关于php配置参数

没事查看了一下php日志,发现提示进程数不够,日志信息如下:
WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 15 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 16 total children NOTICE: Finishing ... NOTICE: exiting, bye-bye! NOTICE: fpm is running, pid 31023 NOTICE: ready to handle connections WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 17 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 17 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 19 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 17 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 15 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 17 total children WARNING: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 21 total children
使用下面的命令查看php进程:# ps -ef |grep phproot   25874 209070 11:56 pts/0    00:00:00 more index.phpwww      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 259110 12:03 pts/1    00:00:00 grep phproot   31023   10 Nov04 ?      00:00:09 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
内存占用情况:只用了2G左右的内存# free -m             total       used       free   shared    buffers   cachedMem:         19990      19685      304          0      256      16949-/+ buffers/cache:       2480      17509Swap:      19999      112      19887

打开配置文件php-fpm.conf发现:pm.max_children = 5



修改成如下参数后,发现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
# ps -ef |grep php |wc -l
515
修改php配置文件后,内存占用从2G变成了6.8G左右,增长了4.8G左右,一个php进程开销占到了8M左右,这个可以根据实际的内存情况来进行修改。
# 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,可能有效果。
页: [1]
查看完整版本: 关于php配置参数