大网数据广告活动
服务器运维问答

PHP-FPM using 100% CPU on a server that has 16 threads

· 52CE 我爱测

I have a server that has 32 GB of RAM and 16 threads. This server has an API in PHP that receives many requests from other external APIs, I made a configuration in PHP-FPM to support all these requests without slowing down the si…

问题原文

原帖链接 · Vinicius Aquino · CC BY-SA 4.0

I have a server that has 32 GB of RAM and 16 threads. This server has an API in PHP that receives many requests from other external APIs, I made a configuration in PHP-FPM to support all these requests without slowing down the site, this worked well for 1 year, now the requests have practically doubled and this is leaving website pages are slow, taking 5-6 seconds to load, which is not normal. Maybe I have to redo a configuration in PHP-FPM to support this new demand for requests, what would you do in this situation?

My server has 32 GB of RAM, but uses only 2.5 GB, is that okay? Is it possible to maintain a balance between RAM and CPU to improve CPU performance or am I talking nonsense?

pm.max_children = 32
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 1000

htop command output

There are 32 children of PHP-FPM running the processes.

已采纳解答

原帖链接 · Bogdan Stoica · CC BY-SA 4.0

I would use php-fpm settings with pm = static. From my experience high traffic websites work better with pm static rather than dynamic/ondemand.

You can get an ideea about the memory used by a php-fpm process using the command bellow:

ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'

I would modify the php-fpm config with something like this:

pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 1000

Restart php-fpm afterwards!

As a side note, here's a very interesting article that can explain a lot and guide you to find the best configuration: https://thisinterestsme.com/php-fpm-settings/

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-03-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。