Nginx + php-fpm – recv() error

mysql5nginxphp-fpm

I get the follow error in the nginx log

[error] 17734#0: *6643 recv() failed (104: Connection reset by peer)
while reading response header from upstream, client: [cut],
server: [cut], request: "GET /venues HTTP/1.1", upstream:
"fastcgi://127.0.0.1:9000", host: "[cut]"

I have a dedicated box with 8 gb ram, quad core chip. Good server.
Nginx, php-fpm & mysql all latest versions running under ubuntu 10.04

I only get this when I stress test the server with siege. If I increase the number of concurrent connections to 100, I can get up to 20% of all requests to fail.

Furthermore, I don't get this on pages that have no mysql queries. And only a few failures on pages with moderate number of queries. Bit, I'm not sure if that's got to do anything with it.

I have a feeling this is something to do with php. But I can't figure it out.

Any suggestions of where to even start looking?

Update: and the php error log is silent. No record of anything going wrong

Best Answer

Most probably you ran out of php-fpm workers. The log was silent because nothing was wrong in the code itself - workers just were busy processing your requests. If you did not get this on pages without MySQL queries, the bottleneck was the MySQL DB. You should identify long-running queries (using mytop or slow log feature or maybe some custom PHP logging around your SQL processing) and optimize them. Of course, "long queries" are actually quite short in high-load we world. Even 200ms query is long enough to put your server on its knees.