PHP-FPM performing worse than mod_php
- by lordstyx
Recently the website I maintain has been growing a lot and I saw the point coming where I'd want to switch from apache to nginx, because I kept on reading that it performs way better.
Now I've done the switch, and I have to say, nginx is keeping up just fine. However, php-fpm is forming a problem.
Where the php pages used to take 0.1 second to generate with the same load they now take around 3 seconds!
Furthermore the error.log from nginx is being spammed with errors like:
upstream timed out (110: Connection timed out) while connecting to upstream, client: ...
I also tried using unix sockets instead, but those would complain about the following:
connect() to unix:/tmp/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream
I've fiddled with settings here and there but nothing seems to work. Changing the amount of pm.max_children doesn't seem to help a lot either, but with it's current amount at 350 it seems to be the lesser of all evil.
The server that's being used has 3 GB RAM (not all of it is free due to a MySQL server also running) along with 2 dual-core processors (4 cores in total).
Am I doing something majorly wrong with the settings here, or is the server simply not capable enough?
EDIT:
Here is the nginx server block
server {
listen 80;
listen [::]:80 default ipv6only=on;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
try_files $uri = 404;
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
And the php-fpm pool:
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
;listen = /tmp/php5-fpm.sock
listen.backlog = -1
pm = dynamic
pm.max_children = 350
pm.start_servers = 200
pm.min_spare_servers = 10
pm.max_spare_servers = 350
pm.max_requests = 1536
rlimit_files = 65536
rlimit_core = unlimited
chdir = /