php-fpm占用内存过高 怎么定位

2025-05-04 22:01:34
推荐回答(1个)
回答1:

  NGINX下PHP-FPM占用内存状态及进程数调整
  网站出现500,查看SLOWLOG日志发现如下提示:
  [html] view plain copy 在CODE上查看代码片派生到我的代码片
  WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 8 idle, and 58 total children
  WARNING: [pool www] server reached pm.max_children setting (50), consider raising it
  昨天晚上刚改的看来又不够用了!
  查看PHP-FPM内存占用的几个有用小命令,记录如下:
  1.查看每个FPM的内存占用:
  [vb] view plain copy 在CODE上查看代码片派生到我的代码片
  ps -ylC php-fpm --sort:rss
  当然,在后后面加 | wc -l可查看系统当前FPM总进程数,我的目前在45个左右。
  PHP官方的建议设置值:
  pm.max_children = Total RAM dedicated to the web server / Max child process size
  2.查看FPM在你的机子上的平均内存占用:
  [python] view plain copy 在CODE上查看代码片派生到我的代码片
  ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'