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/

  • 相关阅读:
    小程序 wx.navigateTo和 wx.redirectTo区别
    小程序返回上一级页面背景音乐报错 setBackgroundAudioState:fail title is nil!;
    centos7 安装RabbitMQ3.6.15 以及各种报错
    MYSQL创建分区时候报错
    scrapy操作mysql/批量下载图片
    深入浅出TCP与IP协议笔记
    python反射详解
    python迭代器
    python生成器
    loggong模块
  • 原文地址:https://www.cnblogs.com/paul8339/p/6014715.html
Copyright © 2011-2022 走看看