php-fpm配置调整
问题分析:
接口卡顿异常 seems too busy
查找php慢日志:/etc/php-fpm.d/www.conf
看到慢日志路径:
slowlog = /var/log/php-fpm/www-slow.log
开始优化:
1.根据服务器内存判断一个php进程占用多少空间
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
服务器有8GB的RAM,所以:
pm.max_children = 6144MB / 85MB = 72
当pm = dynamic 动态时,下面三个参数都有效
pm.max_children = 50 //最大进程数 pm.start_servers = 5 //开始进程数 注意公式: start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2 pm.min_spare_servers = 5 //最小空闲进程数 pm.max_spare_servers = 35 //最大空闲进程数
当pm = static模式时,只有pm.max_children生效
pm.max_children = 50 //最大进程数
合适设置进程数。
参考8核心16G为例:
pm = dynamic
pm.max_children = 32 (8*4)
pm.start_servers = 24 (8*3)
pm.min_spare_servers = 20 (8*2.5)
pm.max_spare_servers = 28 (8*3.5)
龙卷风之殇