Friday, April 9, 2010

nginx php-fpm TIME_WAIT

When you use nginx as a fastcgi web server and php-fpm for workers, you might come arocss TCP TIME_WAIT problem.
TIME_WAIT is a state of socket waiting for a certain amount of time to close.

Because of the very frequent communications between nginx and php-fpm, you will find sockets of TIME_WAIT accumulating a lot over 30,000. It looks uncomfortable.

The solution is to use a unix domain socket.

1. php-fpm.con
/tmp/fastcgi.sock

2. nginx.conf
fastcgi_pass unix:/tmp/fastcgi.sock;

you will find a great reduction in the number of sockets of TIME_WAIT.
However, from my test the performance is worse than TCP socket.
I don't know why...

Anyway, the result from my benchmark test, nginx was able to process 4~5 times more requests(10,000 units per sec) as Apache did. it's awesome.

0 comments:

Post a Comment