为了账号安全,请及时绑定邮箱和手机立即绑定

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)

00007fffc568b000     80K rwx--    [ stack ]

00007fffc569f000      4K rw---    [ anon ]

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

ffffffffff600000   8192K -----    [ anon ]

 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

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



点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

0 评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

举报

0/150
提交
取消