Php-fpm7.0 consuming almost 80% of CPU and 130% RAM!

So yesterday I transferred my woocommerce website from Siteground to EE v3 after the transfer the website admin dashboard was very slow and after some time it became impossible for me to even deactivate WordPress plugins from the dashboard. When I checked the Digitalocean dashboad the CPU and RAM usage of php-fpm7.0 was 80% and 130% but in the memory graph the usage was not more than 70%

My website doesn’t have many visits, The server is unresponsive the only change I made was to the site-available/my-website.com for the https and www to non-www redirection.

I m using FastCGI with w3 cache plugin I have already disabled wp_cron on the website.

Here are my conf

www.conf

[www]

user = www-data

group = www-data

listen = 127.0.0.1:9070

listen.owner = www-data

listen.group = www-data

pm = ondemand

pm.max_children = 20

pm.start_servers = 20

pm.min_spare_servers = 10

pm.max_spare_servers = 30

ping.path = /ping

pm.status_path = /status

pm.max_requests = 500

request_terminate_timeout = 300

fpm.log

[24-Nov-2018 12:19:20] WARNING: [pool www] child 26727, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.454683 sec), terminating

[24-Nov-2018 12:19:20] WARNING: [pool www] child 26727 exited on signal 15 (SIGTERM) after 2747.529670 seconds from start

[24-Nov-2018 12:19:20] NOTICE: [pool www] child 27681 started

[24-Nov-2018 12:44:17] WARNING: [pool www] child 26552, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (301.180776 sec), terminating

[24-Nov-2018 12:44:17] WARNING: [pool www] child 26552 exited on signal 15 (SIGTERM) after 4819.021790 seconds from start

[24-Nov-2018 12:44:17] NOTICE: [pool www] child 28148 started

[24-Nov-2018 12:44:27] WARNING: [pool www] child 26550, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (302.332592 sec), terminating

[24-Nov-2018 12:44:27] WARNING: [pool www] child 26550 exited on signal 15 (SIGTERM) after 4829.170910 seconds from start

[24-Nov-2018 12:44:27] NOTICE: [pool www] child 28149 started

[24-Nov-2018 13:24:04] WARNING: [pool www] child 27182, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.100235 sec), terminating

[24-Nov-2018 13:24:05] WARNING: [pool www] child 27182 exited on signal 15 (SIGTERM) after 5251.762017 seconds from start

[24-Nov-2018 13:24:05] NOTICE: [pool www] child 28902 started

[24-Nov-2018 13:31:25] WARNING: [pool www] child 26562, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (301.501065 sec), terminating

[24-Nov-2018 13:31:25] WARNING: [pool www] child 26562 exited on signal 15 (SIGTERM) after 7636.992029 seconds from start

[24-Nov-2018 13:31:25] NOTICE: [pool www] child 28991 started

[24-Nov-2018 13:47:55] WARNING: [pool www] child 26556, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (301.032356 sec), terminating

[24-Nov-2018 13:47:55] WARNING: [pool www] child 26556 exited on signal 15 (SIGTERM) after 8635.579325 seconds from start

[24-Nov-2018 13:47:55] NOTICE: [pool www] child 29306 started

[24-Nov-2018 13:51:42] WARNING: [pool www] child 28149, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (303.177641 sec), terminating

[24-Nov-2018 13:51:42] WARNING: [pool www] child 28149 exited on signal 15 (SIGTERM) after 4034.619237 seconds from start

[24-Nov-2018 13:51:42] NOTICE: [pool www] child 29347 started

[24-Nov-2018 14:23:52] WARNING: [pool www] child 26555, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (302.304256 sec), terminating

[24-Nov-2018 14:23:52] WARNING: [pool www] child 26555 exited on signal 15 (SIGTERM) after 10793.380304 seconds from start

[24-Nov-2018 14:23:52] NOTICE: [pool www] child 29937 started

[24-Nov-2018 14:37:29] WARNING: [pool www] child 28148, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.451145 sec), terminating

[24-Nov-2018 14:37:29] WARNING: [pool www] child 28148 exited on signal 15 (SIGTERM) after 6792.114833 seconds from start

[24-Nov-2018 14:37:29] NOTICE: [pool www] child 30178 started

[24-Nov-2018 14:37:42] WARNING: [pool www] child 26558, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.195847 sec), terminating

[24-Nov-2018 14:37:43] WARNING: [pool www] child 26558 exited on signal 15 (SIGTERM) after 11622.884400 seconds from start

[24-Nov-2018 14:37:43] NOTICE: [pool www] child 30182 started

[24-Nov-2018 14:44:46] WARNING: [pool www] child 27681, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.736434 sec), terminating

[24-Nov-2018 14:44:46] WARNING: [pool www] child 27681 exited on signal 15 (SIGTERM) after 8726.170457 seconds from start

[24-Nov-2018 14:44:46] NOTICE: [pool www] child 30364 started

[24-Nov-2018 15:48:07] WARNING: [pool www] child 26712, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (303.319727 sec), terminating

[24-Nov-2018 15:48:07] WARNING: [pool www] child 26712 exited on signal 15 (SIGTERM) after 15348.378186 seconds from start

[24-Nov-2018 15:48:07] NOTICE: [pool www] child 31508 started

[24-Nov-2018 15:49:18] NOTICE: Reloading in progress ...

[24-Nov-2018 15:49:18] NOTICE: reloading: execvp("/usr/sbin/php-fpm7.0", {"/usr/sbin/php-fpm7.0", "--nodaemonize", "--fpm-config", "/etc/php/7.0/fpm/php-fpm.conf"})

[24-Nov-2018 15:49:18] NOTICE: using inherited socket fd=8, "127.0.0.1:9170"

[24-Nov-2018 15:49:18] NOTICE: using inherited socket fd=8, "127.0.0.1:9170"

[24-Nov-2018 15:49:18] NOTICE: using inherited socket fd=9, "127.0.0.1:9070"

[24-Nov-2018 15:49:18] NOTICE: using inherited socket fd=9, "127.0.0.1:9070"

[24-Nov-2018 15:49:18] NOTICE: fpm is running, pid 4152

[24-Nov-2018 15:49:18] NOTICE: ready to handle connections

[24-Nov-2018 15:49:18] NOTICE: systemd monitor interval set to 10000ms

[24-Nov-2018 15:49:26] WARNING: [pool www] server reached max_children setting (20), consider raising it

[24-Nov-2018 16:00:45] WARNING: [pool www] child 31691, script '/var/www/example.com/htdocs/index.php' (request: "GET /index.php") execution timed out (300.933992 sec), terminating

[24-Nov-2018 16:00:45] WARNING: [pool www] child 31691 exited on signal 15 (SIGTERM) after 685.227617 seconds from start

[24-Nov-2018 16:00:45] NOTICE: [pool www] child 31934 started

And here’s the etc/nginx/sites-available/example.com conf

server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;

	server_name example.com;
	root /var/www/example.com/htdocs;

	access_log /var/log/nginx/example.com.access.log rt_cache;
    error_log /var/log/nginx/example.com.error.log;

	# index.php
	index index.php index.html index.htm;

    include common/wpfc-php7.conf;  
    include common/wpcommon-php7.conf;
    include common/locations-php7.conf;
    include /var/www/example.com/conf/nginx/*.conf;
}

# subdomains redirect
server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;

	server_name *.example.com;

	return 301 https://example.com$request_uri;
}

# HTTP redirect
server {
	listen 80;
	listen [::]:80;

	server_name .example.com;

	location / {
		return 301 https://example.com$request_uri;
	}
}

I had an issue like this, but it wasn’t as extreme. only like 40% CPU usage. I was able to get things back under control by limiting the timeout of wp-cron in wp-config.php

Some say you should disable wp-cron altogether and set up a real cronjob to do the work at a predetermined set of time.

I have already disabled wp-cron and setup a real cronjob but the problem is still there.

Hello,

at first, you php-fpm pool configuration isn’t really efficient, because you limit php-fpm max children to 20 but you also set start_servers to 20. So there is always 20 php-fpm childrens.

You can keep the original EasyEngine pool configuration which work for almost all sites :

[www]
user = www-data
group = www-data
listen = 127.0.0.1:9090
listen.owner = www-data
listen.group = www-data
pm = ondemand
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
ping.path = /ping
pm.status_path = /status
pm.max_requests = 500
request_terminate_timeout = 300

But high resource usage is probably due to wp-cron jobs, especially with Woocommerce.
You can set a timeout for wp-cron in your wp-config.php :

/* CRON */
define( 'DISABLE_WP_CRON',      'true' );
define( 'ALTERNATE_WP_CRON',    'true' );
define( 'WP_CRON_LOCK_TIMEOUT', 60 );