nginx: optimum # of workers

I just bought a new server which will be running nginx, PHP, MySQL stack that will be serving fully-cached html requests 90% of the time and PHP/mysql requests otherwise through FastCGI.

Stats on the box are:

CentOS 5.x 64-bit

2x Intel Quad Core Xeon E5520 (8 cores/16 threads)

6GB DDR3 @ 800Mhz

Wondering what some nginx pros would generally recommend regarding number of worker processes for a server like this. Am looking for optimum setup here as this is strictly a web server - will ideally be serving a few thousand requests/sec from html cache and a few hundred max from PHP/mysql.

Thanks!


Solution 1:

Nginx's resident memory usage is trivial and to the best of my knowledge there is little penalty for having 8 Nginx processes (1 per core) rather than 1.

I would run apache bench or another utiltiy with high concurrency requesting disk heavy objects. Keep increasing the AB tests till you discover the breaking point. Then experiment with the amount of Nginx procs keeping all other tests equal. Report back so we can all be the wiser.

Solution 2:

If you are doing a proxying workload (PHP counts as a proxying workload) then I would recommend only one worker as there is no reason to use more than one.

The only reason I would recommend more than one worker is when you are using nginx for heavy static file IO. Even though nginx uses an asynchronous IO model, there are still a few system calls that can block the progress of the worker, reading from disk is one of those. In those cases I would recommend one worker per disk spindle, or CPU, whichever is the smaller.

Solution 3:

Take a look at number of nginx worker processes