zoukankan      html  css  js  c++  java
  • PHP fpm优化【转】

    在优化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

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

    转自

    PHP fpm优化 - 信不信由你 - 51CTO技术博客
    http://312461613.blog.51cto.com/965442/1559672/

  • 相关阅读:
    动态规划解按摩师的最长预约时间
    C#中WinForm的Tab键顺序调整顺序
    内网穿透工具对比FRP+NPS+Zerotier与NAT服务器测试
    " " 和 ' ' 混用拼接html字符串,且含有事件,事件中有参数
    HAProxy在Windows下实现负载均衡与反向代理
    react 导入src外部的文件 Relative imports outside of src/ are not supported.
    11_实例
    C#删除指定目录下文件(保留指定几天前的日志文件)
    【转】系统创建定时执行任务bat批处理删除指定N天前文件夹的文件
    mariadb导如数据异常------Error Code: 1153
  • 原文地址:https://www.cnblogs.com/paul8339/p/6014715.html
Copyright © 2011-2022 走看看