PHP-FPM Processor Load | IT Admins Group
 

PHP-FPM Processor Load

I run just about everything in Proxmox/OpenVZ containers. Recently I noticed after doing a fresh install of PHP-FPM that the pools for PHP-FPM were eating up a LOT of CPU time. That PHP-FPM can eat up a processor is nothing new. However, the pools were doing absolutely nothing. They were just idling there and were causing ca. 40% load on the processor.

First I had to find out why PHP-FPM was eating up my processor and therefore the use of “strace” was called for.


ps auxf
strace -ffttTo strace.txt -p 8766

Basically I grabbed the PID of a running php-fpm process that was causing massive load and fed that to strace. After that I noticed the following in the file:


12:32:14.981209 gettimeofday({1380364334, 981222}, NULL) = 0 <0.000008>
12:32:14.981249 gettimeofday({1380364334, 981261}, NULL) = 0 <0.000008>
12:32:14.981297 gettimeofday({1380364334, 981310}, NULL) = 0 <0.000009>
12:32:14.981337 gettimeofday({1380364334, 981350}, NULL) = 0 <0.000009>
12:32:14.981379 gettimeofday({1380364334, 981392}, NULL) = 0 <0.000008>
12:32:14.981418 gettimeofday({1380364334, 981431}, NULL) = 0 <0.000008>
12:32:14.981464 gettimeofday({1380364334, 981477}, NULL) = 0 <0.000009>
12:32:14.981504 gettimeofday({1380364334, 981517}, NULL) = 0 <0.000008>
12:32:14.981545 gettimeofday({1380364334, 981558}, NULL) = 0 <0.000010>
12:32:14.981588 gettimeofday({1380364334, 981601}, NULL) = 0 <0.000008>
12:32:14.981633 gettimeofday({1380364334, 981646}, NULL) = 0 <0.000009>
12:32:14.981673 gettimeofday({1380364334, 981685}, NULL) = 0 <0.000008>
12:32:14.981714 gettimeofday({1380364334, 981727}, NULL) = 0 <0.000008>
12:32:14.981753 gettimeofday({1380364334, 981766}, NULL) = 0 <0.000008>
12:32:14.981798 gettimeofday({1380364334, 981810}, NULL) = 0 <0.000008>
12:32:14.981837 gettimeofday({1380364334, 981850}, NULL) = 0 <0.000008>
12:32:14.981879 gettimeofday({1380364334, 981891}, NULL) = 0 <0.000009>
12:32:14.981917 gettimeofday({1380364334, 981930}, NULL) = 0 <0.000008>
12:32:14.981963 gettimeofday({1380364334, 981976}, NULL) = 0 <0.000008>
12:32:14.982003 gettimeofday({1380364334, 982016}, NULL) = 0 <0.000009>
12:32:14.982044 gettimeofday({1380364334, 982057}, NULL) = 0 <0.000009>
12:32:14.982084 gettimeofday({1380364334, 982096}, NULL) = 0 <0.000009>
12:32:14.982130 gettimeofday({1380364334, 982143}, NULL) = 0 <0.000008>
12:32:14.982170 gettimeofday({1380364334, 982182}, NULL) = 0 <0.000009>
12:32:14.982211 gettimeofday({1380364334, 982223}, NULL) = 0 <0.000008>
12:32:14.982250 gettimeofday({1380364334, 982263}, NULL) = 0 <0.000008>
12:32:14.982296 gettimeofday({1380364334, 982309}, NULL) = 0 <0.000013>
12:32:14.982342 gettimeofday({1380364334, 982355}, NULL) = 0 <0.000008>
12:32:14.982397 gettimeofday({1380364334, 982411}, NULL) = 0 <0.000009>
12:32:14.982438 gettimeofday({1380364334, 982451}, NULL) = 0 <0.000008>
12:32:14.982483 gettimeofday({1380364334, 982499}, NULL) = 0 <0.000012>
12:32:14.982528 gettimeofday({1380364334, 982540}, NULL) = 0 <0.000008>

Such entries went on and on and on. So apparently PHP-FPM had a problem getting the time of day.

The interesting part of this is that the call to gettimeofday goes through /dev/timedev which is not available in a standard OpenVZ container. So to see if that was actually the problem I just did the following:


mknod /dev/timedev c 15 0
chmod 644 /dev/timedev

The load on the server dropped immediately and has since been a very well behaved container.

Now the only thing to do is make sure that /dev/timedev is available every time the container starts. This is also not very difficult to remedy. From the Host node you will need to allow access to /dev/timedev


vzctl set CTID –devices c:15:0:r –save
vzctl exec CTID mknod /dev/timedev c 15 0
vzctl exec CTID chmod 644 /dev/timedev

Now you are set for the next restart of the container and PHP-FPM should not be causing any further problems.

One response to “PHP-FPM Processor Load”

  1. Hi… this fix works for docker?

Leave a Reply

 
heat
heat
heat
heat