carlosv
By:
carlosv

High CPU usage PHP-FPM

May 28, 2017 3.5k views
Applications DigitalOcean Ubuntu 16.04

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

2 comments
3 Answers

@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.

@jtittle

Thank you very much for replying!

Perhaps I failed to provide details required to better assess this scenario: :

  • I'm using WP Rocket plugin for caching.
  • the application is currently in a 32 gb RAM, 12 core CPU, 320 GB droplet

I didn't use Redis because it was not provided by ServerPilot, but I'll take a look at it.

As per fine tuning the stack I do not have any experience at all in doing so. Do you provide consulting services? Or do you happen to know someone that might help me with this?

Thanks,

I'd also strongly recommend ensuring you're using PHP 7.0 with Opcache, implementing proper database tuning, and as mentioned earlier, implementing WP Super Cache/Total Cache.

The first 2 should have a huge impact, with database tuning allowing you to store more in memory for considerably faster query execution times.

Have another answer? Share your knowledge.