设为首页 收藏本站
查看: 662|回复: 0

[经验分享] 关于php配置参数

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-6 09:16:42 | 显示全部楼层 |阅读模式
没事查看了一下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进程:
[iyunv@test ~]# 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左右的内存
[iyunv@test 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
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
[iyunv@test etc]# ps -ef |grep php |wc -l
515
修改php配置文件后,内存占用从2G变成了6.8G左右,增长了4.8G左右,一个php进程开销占到了8M左右,这个可以根据实际的内存情况来进行修改。
[iyunv@localhost 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,可能有效果。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-27233-1-1.html 上篇帖子: php链接mysql代码测试 下篇帖子: php查询多个门户网站页面搜索结果简单代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表