msklut
msklut

Reputation: 81

PHP-FPM processes causing high CPU usage on VPS

A few months ago we moved our e-commerce website to a VPS, after struggling with poor performance from shared hosting platforms. To handle an increase in traffic (avg. 300-500 daily visitors), we tweaked our PHP-FPM settings and increased the Max Children from 5 (default) to 50. Currently, PHP-FPM "pool" processes are requiring high CPU usage (30-40%). Any tips to make those "pool" processes use less CPU? Thanks!

VPS Specs:
2 CPUs
Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
4GB RAM

WHM: Centos 7.8 v86.0.18
Ecommerce platform: OpenCart 3.0.2.0

Upvotes: 2

Views: 13003

Answers (1)

Sammitch
Sammitch

Reputation: 32232

  1. FPM has nothing to do with the CPU usage, it's your code.
  2. That said, don't just arbitrarily change the number of worker processes without a sound basis to do so, eg: actual resource statistics.
    • With 300-500 daily users you're really unlikely to have 50 concurrent requests unless you're doing something strange.
    • The place I'm currently working at peaks at about 600 concurrent users and a grand maximum of 15-20 connections actually simultaneously doing anything. [Note: Much larger/broader backing infrastructure]
    • Do you really expect each CPU core to handle 25 simultaneous requests?
    • Can you reasonably fit 50 requests' worth of RAM into that 4GB?
    • Are you fine with those 50 idle PHP processes each consuming 10-15MB RAM apiece?

All that said, we can't tell you what in your code is using up resources, and it's not possible for you to post enough information for us to make more than a vague guess. You need to put things in place to measure where that resource usage is happening, profile your code to find out why, and tune your infrastructure configuration to accommodate your specific application requirements.

There's no one "magic" config that works for everyone.

Upvotes: 3

Related Questions