Aug 10, 2011
tom

Server slow response: ps aux shows many php5-fpm processes

Question

I have just finished setting up my own VPS with the following specs: 2 Ghz single core CPU and 1 GB RAM.

I’m using nginx for my webserver needs. I installed Ruby on Rails, Phusion Passenger, mysql and php5-fpm.

I uploaded a WordPress blog and am experiencing slow responsiveness: http://cl.ly/6Hks. CPU load is about 10-20% when requesting a page.

When I look at ps aux I see the following output:

root       896  0.0  0.3  40916  4080 ?        Ss   10:49   0:00 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   897  0.1  3.2  66488 33260 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   898  0.1  2.0  54660 21084 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   899  0.1  3.1  66468 32040 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   900  0.1  3.1  66492 32196 ?        S    10:49   0:05 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   901  0.1  3.1  66984 32300 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   902  0.1  3.2  68040 33648 ?        S    10:49   0:05 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   903  0.1  3.3  68364 33924 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   904  0.1  3.3  68348 34088 ?        S    10:49   0:05 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   905  0.1  3.3  68572 34140 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf
www-data   906  0.1  3.1  66500 32068 ?        S    10:49   0:04 /usr/bin/php5-fpm --fpm-config /etc/php5/fpm/php5-fpm.conf

Is it normal to have that many php5-fpm processes?

Also, when I execute a traceroute to a static page on the domain it gets executed very quickly, but when I traceroute the wordpress blog the output is like this:

 1  10.15.206.1 (10.15.206.1)  8.832 ms  9.044 ms  19.764 ms
 2  p7001.net.upc.nl (212.142.7.1)  22.976 ms  10.605 ms  12.005 ms
 3  84.116.244.21 (84.116.244.21)  15.661 ms  14.731 ms  15.406 ms
 4  nl-ams04a-ri2-xe-9-1-0.aorta.net (84.116.130.218)  16.405 ms
    nl-ams04a-ri2-xe-9-0-0.aorta.net (84.116.130.170)  27.288 ms
    nl-ams04a-ri2-xe-2-3-0.aorta.net (84.116.134.89)  13.824 ms
 5  te7-1-10g.ar2.ams1.gblx.net (64.212.107.49)  15.009 ms
    208.178.58.193 (208.178.58.193)  14.877 ms  15.392 ms
 6  nominum.port-c2.552.406.ar4.lon3.gblx.net (64.210.69.250)  26.768 ms  24.410 ms  21.830 ms
 7  81.200.66.253 (81.200.66.253)  27.068 ms  23.849 ms  24.113 ms
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * *^C

Eventually I just exit the process because there’s no end to it.

Answer

First off, there’s no such a thing as traceroute to a static/dynamic page. It’s done on a host level. So unless you’re using different servers for hosting static content and dynamic pages, traceroute won’t be really helpful in that case.

As to the number of spawned php processes – this is entirely configurable and should be balanced between resources you have and the load you expect to have. The thing is you want as many processes as you can handle (to serve multiple concurrent users without waiting in queue), but at the same time don’t want to deplete your memory completely. If your server starts swapping the performance will degrade severely.

You can try diagnosing this situation a bit more by checking your current memory usage (free -m or top) and verifying if you’re not hitting some limit here.

That said, I don’t know what your statistic is, is this 536ms request time for the main page only? It may not be brilliant, but it’s not that bad either. Try comparing this with some static pages and other PHP applications to see where the problem lies. WordPress without caching may not be the fastest under the sun, but you can try optimizing things later on if you know what’s causing the problem.

Related posts:

  1. php5-fpm + nginx + drupal7 : keeps sending me index.php for download
  2. Debian/Nginx/PHP5-FPM on Xen. Is it the right choice?
  3. Nginx and PHP FPM is slow
  4. Optimizing fastcgi + php5
  5. What is wrong in my php-fpm configuration?

Leave a comment