High CPU load from php-fpm


#1

I run 2 wordpress sites that receive about 50k hits in total a day. They both have w3total cache enabled. I noticed my vps has a slightly high cpu load. This is what top looks like:

top - 21:03:44 up 4 days,  3:52,  1 user,  load average: 5.06, 4.56, 4.51
Tasks:  63 total,   1 running,  62 sleeping,   0 stopped,   0 zombie
%Cpu(s): 18.1 us,  3.1 sy,  0.0 ni, 75.6 id,  2.8 wa,  0.0 hi,  0.4 si,  0.0 st
KiB Mem:   8388608 total,  8273624 used,   114984 free,        0 buffers
KiB Swap:   524288 total,        0 used,   524288 free.  6963472 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
12721 www-data  20   0  477500 102560  80252 S  17.6  1.2   0:55.07 php-fpm5.6
12483 www-data  20   0  503648 129632  81156 S  12.6  1.5   1:35.04 php-fpm5.6
12385 www-data  20   0  495632 121840  81604 S   9.0  1.5   2:08.49 php-fpm5.6
12441 www-data  20   0  483256 109616  81580 S   4.0  1.3   1:39.73 php-fpm5.6
12464 www-data  20   0  484512 110512  81192 S   3.3  1.3   1:39.07 php-fpm5.6
 2055 mysql     20   0 2141564 556228  14552 S   1.0  6.6 594:45.21 mysqld
 2235 memcache  20   0  394844  78580   2336 S   0.7  0.9 140:48.05 memcached
12729 www-data  20   0  478332 103392  80252 S   0.7  1.2   0:56.09 php-fpm5.6
 2069 www-data  20   0  214944  13928   5396 S   0.3  0.2   1:30.97 nginx
 2074 www-data  20   0  214944  13596   5396 S   0.3  0.2   1:25.78 nginx
12485 www-data  20   0  479620 105700  81272 S   0.3  1.3   1:25.96 php-fpm5.6
    1 root      20   0   33120   3092   2156 S   0.0  0.0   0:00.54 init
  478 root      20   0   19480    176      0 S   0.0  0.0   0:00.03 upstart-udev-br
  617 root      20   0   49268   2916   2496 S   0.0  0.0   0:02.95 systemd-udevd
  730 root      20   0   15524   1820   1308 S   0.0  0.0   0:00.03 upstart-socket-
 1060 root      20   0   15280    204      0 S   0.0  0.0   0:00.01 upstart-file-br
 1390 syslog    20   0  180044   4960   2176 S   0.0  0.1   0:00.72 rsyslogd
 1681 root      20   0   23656   2284   2028 S   0.0  0.0   0:00.41 cron
 1689 root      20   0  387844  35372  27676 S   0.0  0.4   0:32.67 php-fpm5.6
 1789 root      20   0   61384   5300   4624 S   0.0  0.1   0:00.58 sshd
 1845 root      20   0   18224   3248   2744 S   0.0  0.0   0:00.02 mysqld_safe
 2056 root      20   0    4344   1588   1484 S   0.0  0.0   0:00.00 logger
 2068 root      20   0  210848   6200   1648 S   0.0  0.1   0:00.01 nginx
 2071 www-data  20   0  216992  15976   5392 S   0.0  0.2   1:33.71 nginx
 2072 www-data  20   0  214944  13788   5392 S   0.0  0.2   1:27.90 nginx
 2073 www-data  20   0  214944  14052   5396 S   0.0  0.2   1:26.75 nginx
 2075 www-data  20   0  213920  13120   5396 S   0.0  0.2   1:27.46 nginx
 2076 www-data  20   0  214944  13860   5396 S   0.0  0.2   1:29.46 nginx
 2077 www-data  20   0  215968  14920   5392 S   0.0  0.2   1:27.25 nginx
 2078 www-data  20   0  214944  13780   5396 S   0.0  0.2   1:32.38 nginx
 2079 www-data  20   0  214944  13548   5392 S   0.0  0.2   1:30.17 nginx
 2080 www-data  20   0  215968  14724   5164 S   0.0  0.2   1:31.07 nginx
 2081 www-data  20   0  216992  15712   5200 S   0.0  0.2   1:28.56 nginx
 2082 www-data  20   0  214944  13692   5260 S   0.0  0.2   1:26.82 nginx
 2083 www-data  20   0  214944  14084   5292 S   0.0  0.2   1:29.20 nginx
 2084 www-data  20   0  213920  12612   5396 S   0.0  0.2   1:26.95 nginx
 2085 www-data  20   0  213920  13364   5396 S   0.0  0.2   1:30.72 nginx
 2086 www-data  20   0  215968  14636   5388 S   0.0  0.2   1:26.73 nginx
 2087 www-data  20   0  215968  14888   5396 S   0.0  0.2   1:31.11 nginx
 2088 www-data  20   0  214944  14232   5396 S   0.0  0.2   1:29.50 nginx
 2089 www-data  20   0  215968  15104   5396 S   0.0  0.2   1:30.13 nginx
 2090 www-data  20   0  214944  13864   5396 S   0.0  0.2   1:34.87 nginx
 2091 www-data  20   0  214944  13724   5388 S   0.0  0.2   1:29.85 nginx
 2092 www-data  20   0  214944  14232   5396 S   0.0  0.2   1:22.95 nginx
 2093 www-data  20   0  213920  13108   5396 S   0.0  0.2   1:32.29 nginx
 2094 www-data  20   0  210848   7268   2504 S   0.0  0.1   0:01.43 nginx
 2402 root      20   0   25344   2960   2640 S   0.0  0.0   0:01.65 master
 2414 postfix   20   0   27576   2924   2580 S   0.0  0.0   0:00.18 qmgr
 2440 root      20   0  560504  11236   3840 S   0.0  0.1   8:58.39 fail2ban-server
 2489 root      20   0   12788   1940   1796 S   0.0  0.0   0:00.00 getty
 2491 root      20   0   12788   1876   1724 S   0.0  0.0   0:00.00 getty
 2492 root      20   0   12788   1900   1756 S   0.0  0.0   0:00.00 getty
 2605 postfix   20   0   40180   5244   4696 S   0.0  0.1   0:00.21 tlsmgr
11671 postfix   20   0   27408   2916   2636 S   0.0  0.0   0:00.00 pickup
12351 www-data  20   0  487088 112680  81144 S   0.0  1.3   2:08.05 php-fpm5.6
12360 www-data  20   0  487332 115156  83020 S   0.0  1.4   2:03.74 php-fpm5.6

The high cpu load seems to be coming from php-fpm. Does anyone know how can I reduce it? my vps has 8gb ram & 4 cpu of Intel® Xeon® CPU X5650 @ 2.67GHz


#2

First thing, IMHO, is checking if there are published .php scripts slowing down your server.

Try something like:

tail -f /var/log/nginx/*.access.log | grep -w php

This will list in real time which scripts are being accessed “out” of WordPress (CTRL-C to stop the listing).

In case there are lots of admin-ajax.php hits, you should analyse your plugins and theme to find out what’s causing such requests.


#3

This is what the log says:

185.112.157.139 0.730 - [12/Jan/2018:23:12:22 -0500] domain.com "POST /wp-cron.php?doing_wp_cron=1515816741.7454619407653808593750 HTTP/1.1" 200 31 "https://domain.com/wp-cron.php?doing_wp_cron=1515816741.7454619407653808593750" "WordPress/4.7.8; https://domain.com"
185.112.157.139 - - [12/Jan/2018:23:12:24 -0500] www.domain.com "POST /wp-cron.php?doing_wp_cron=1515816743.1502079963684082031250 HTTP/1.1" 499 0 "http://www.domain.com/wp-cron.php?doing_wp_cron=1515816743.1502079963684082031250" "WordPress/4.7.8; http://www.domain.com"
185.112.157.139 - - [12/Jan/2018:23:13:53 -0500] domain.com "POST /wp-cron.php?doing_wp_cron=1515816832.8497080802917480468750 HTTP/1.1" 499 0 "https://domain.com/wp-cron.php?doing_wp_cron=1515816832.8497080802917480468750" "WordPress/4.7.8; https://domain.com"
185.112.157.139 - - [12/Jan/2018:23:13:58 -0500] www.domain.com "POST /wp-cron.php?doing_wp_cron=1515816833.2661581039428710937500 HTTP/1.1" 499 0 "http://www.domain.com/wp-cron.php?doing_wp_cron=1515816833.2661581039428710937500" "WordPress/4.7.8; http://www.domain.com"

seems like only wp-cron.php is running but I don’t know what it’s actually doing


#4

@Ruriko,

WP v4.7.8 has a serious vulnerability in it - you should update to at least 4.7.9 .

Also, interesting sites…


#5

@davidsandbrand I’ve updated wordpress to latest version but still have high load.


#6

Using php7.0 will provide better performance, and may decrease CPU load. But, you can also enable the debug_log of wordpress to see if there are issues in your plugins or theme