Question

High CPU usage PHP-FPM

Hi all,

Perhaps this is a silly question but I’ve recently migrated a Wordpress website (http://somosinvictos.com) from another hosting provider to Digital Ocean. I used ServerPilot to config the LEMP/LAMP stack and successfully migrated my website.

I’m really new to all this but I see a strange trend: while mi CPU load goes to the roof when getting close to 1000 active concurrent visitors, my RAM stays flat (around 10% usage). CPU top process graph says that all the load comes from php-fpm and mysql

Do you think this is expected behavior? Do you have any recommendations for this?

Thanks in advance, Carlos

Subscribe
Share

@Dibbyo457 If you want a good fix to your problem get in touch with @jtittle. He helped us a lot with this.

I am having the exact same issue.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, @carlosv, did you get your CPU load fixed? My problem is very similar: I am using WP Rocket, ServerPilot and 32 gb RAM, 8core CPU. When I get more than 1000 active concurrent visitors my php-fmp goes to the roof and my TTFB gets very high. Cheers.

@carlosv

As traffic grows, so will resource usage.

One way to reduce usage is to implement caching so that each page load doesn’t hit the database. There are a number of caching plugins available, though WP Super Cache and W3 Total Cache are probably the most popular.

https://wordpress.org/plugins/wp-super-cache/

https://wordpress.org/plugins/w3-total-cache/

WP Super Cache is a bit easier to setup and works with very little configuration. On the other hand, if you need something more advanced and you plan on using Redis or Memcached to cache (instead of using the disk), W3 Total Cache would be a better, but more complex option.

Personally, I much prefer simple caching using Redis, though it’s a bit more of a manual setup than it would be with the two plugins above. This is a rather simple plugin, but you’ll need to install Redis, and then do some configuration in wp-config.php to get it working as expected.

https://wordpress.org/plugins/redis-cache/

Caching alone, however, isn’t a magic fix-all. Last I recall, the configuration for MySQL and PHP that ServerPilot uses is either the defaults or pretty close to it, so it’s most likely not tuned for higher than average traffic (and by average, I mean very low to low).

Caching works as another layer to improve performance, but you also need to work on tweaking and tuning the stack itself (NGINX/Apache, MySQL, PHP-FPM, etc) to get the most out of what you’ve got.

Upgrading to a higher plan with more CPU might help, though ultimately, with the same configuration and no caching, you’d likely end up as you are now with higher CPU usage due to so much needing to be processed.

I have a very similar problem. And oddly enough, it used to be the other way around. My server would max out of RAM while the CPU was low. It seems this could have to do with PHP-FPM settings such as pm.max_children, pm.max_requests and the mode whether it be dynamic, on demand or static. At the moment I’m using on demand, max children set to 400 and max request left blank. I got about 900 simultaneous visitors each trying to add a product to the cart and checkout. At this point the server slows down as the CPU starts to approach 90% and ram about 14%.

Wordpress Version 5.7.2 WooCommerce Version 5.3.0

Server architecture Linux 4.18.0-240.10.1.el8_3.x86_64 x86_64 Dedicated Server with only one primary website on it. CPU: 8 Core x 3.0 GHz (Intel Xeon Silver 4123) RAM: 96 GB NVMe2 x 1000 GB Hardware RAID 1 Data transfer rate up to:1 Gbps

Web server nginx/1.18.0 PHP version 7.4.18 (Supports 64bit values) PHP SAPI fpm-fcgi PHP max input variables 1000 PHP time limit 240 PHP memory limit 1024M PHP memory limit (only for admin screens) 72000M

PHP-FPM settings in Plesk pm.max_children = 400 pm.max_requests = blank pm = On Demand

Database: Extension mysqli Server version 10.3.27-MariaDB-log Client version mysqlnd 7.4.18

me also same issue

Hi, any news?

I am using php 7.2-fpm, nginx, varnish and apache2 with wordpress, all fine tuned (wp rocket, cloudflare, autooptimze, etc)

but still seeing too much cpu usage from fpm-php on dual core (it will stop serving the sites if it reachs around 100% cpu).

I am running php-fpm on dynamic mode

I really like to know also.

Basically when it is really busy you would expect high CPU usage. Except when i restart the fpm service its all calm after s when its really busy you would see the same spike back again.

Anyone have the solution? I have the same problem a few days ago till now. I am using WP- Rocket and Nginx Cache… Using top command and saw php7.3-fpm using too much CPU with about 400M RAM for each process… It make my site too slow…

Hi am having the same problem with my website. When I run the top command I can see that this website is using around 80%-90% and the website with just 100 concurrent user goes slow. I am running a droplet with 8GB of RAM on CentOS

@jtittle1 @jtittle can you help me as well as i’m also facing the same issue on my droplet.

Hi @jtittle1 I’m having same issue and would love to get your help on how to optimize the stack with my site. I have 8 GB 4 vCPUs 30 GB Droplet and I can see the php-fpm reaches 300% when I hit 3000 concurrent users. I couldnt find a way to send you a message…