Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm setting up nginx to serve a Drupal install, and I seem to find conflicting information on the nginx worker processes setting. One site says you need two, one says you need five, one says one per processor...

How should I pick the number of nginx worker processes? If it makes a difference, it's a guest VM on a VMWare cluster, and I've given it one virtual processor.

share|improve this question
add comment

4 Answers

up vote 12 down vote accepted

Nginx unlike Apache and other process per connection webservers. It uses one master process to start and monitor a small number of worker processes that actually handle the connections. My recommendation is to start with the default number of workers, which is 1.

worker_processes  1;

You will only need to increase this if you find that the nginx worker is spending too much time blocked on IO. This will not by until it is serving many hundreds of requests per second.

You may also find these settings useful.

worker_rlimit_nofile 8192;

events {
    worker_connections  2048;
    use epoll;
}
share|improve this answer
1  
Can you describe what "worker_rlimit_nofile 8192" is used for? –  The Pixel Developer Jun 10 '09 at 16:57
    
wiki.nginx.org/NginxHttpMainModule#worker_rlimit_nofile. This instructs the worker to increase its ulimit. –  Dave Cheney Jun 10 '09 at 17:53
add comment

On SMP systems, at least nCPU worker processes should be started: on quad-core - four etc. That's enougth for proxying.

If you are going to serve some sites with alot of static content, it would be better to add more workers - one per disk.

If your disk subsystem is to poor or load too high, nginx worker processes may become locked on I/O operations and could not serve other requests. In this case you should increase number of worker processes to some suitable value (may be tens), or add some memory for disk cache.

Look into "ps ax" printout: workers that are in "D" state are locked. Increase until get at least nCPU worker processes not blocked.

share|improve this answer
add comment

I'd start with one and add later if it appears to be a problem.

share|improve this answer
add comment

Run your server for a little bit, and check using top or ps what the memory size is of the worker process (you're looking for RSS memory).

Ideally you find a good average for your worker processes.

Then the formula becomes:

memory available for nginx / memory needed by worker = number of processes
share|improve this answer
    
Why would you want to spend it all? –  iny May 8 '09 at 18:23
4  
Nginx is not apache and doesn't need to use all system memory. This is just wasting of resources. General rule of thumb is to use one nginx worker per CPU core. See Vadim's answer for additional hints. –  AlexD May 6 '11 at 6:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.