Nginx and PHP FPM is slow

Solution 1:

dont start so many php servers initially, perhaps consider testing without this block of code too:

open_file_cache max=5000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;

it looks to me like your trying to load too much into ram initially with php though, it also sounds like your website is a little resource intensive based on the memory usage in top, have you considered an opcode cacher like APC? http://pecl.php.net/APC

Solution 2:

I use a similar setup with nginx and php-fpm with APC. The Min and Max Servers are a bit high, I also have a virtual machine with about 500mb of memory per machine. After reading https://stephentanner.com/tuning-php-fpm.html I've tuned my machines to the following.

pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 50

My machines sit with 4 php-fpm processes at about 60mb each eating about 252mb which leaves more resources for nginx/mysql/whatnot.

Give that a try if it doesn't fit your need exactly tune it a bit more.