Monday 24 March 2014

Nginx process structure




Usually Nginx is working in multiple thread mode, there will be a master process, it will prefork multiple children processes called worker processes. 

  • Master is not worked for web client connection and session management. It only manages the children processes.
  • Worker process handles the requests from clients (usually http/https) and servers them. The number of worker processes are decided by configuration

Configuration Syntax

user userid;
worker_processes  [number];   #define how many worker processes
events{
worker_connections [number];                #define how many connection one process can server
}

Sample configuration
user  nginx;
worker_processes  10;

the processes output

root      5031     1  0 13:41 ?        00:00:00 nginx: master process ./nginx
nginx     5032  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5033  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5034  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5035  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5036  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5037  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5038  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5039  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5040  5031  0 13:41 ?        00:00:00 nginx: worker process
nginx     5041  5031  0 13:41 ?        00:00:00 nginx: worker process

process 5031 is the master(parent) process
processes 5032-5041 are the worker (children) process

hardware and core configuration

low traffic website
medium traffic website
high traffic website

CPU : 2 cores,
memory 2GB,
visits ~ 1/s
CPU : 4 cores,
memory 4GB,
visits ~ 50/s
CPU : 8 cores,
memory 12GB,
visits ~ 1000/s




worker_processor 2;
worker_priority -4;
worker_cpu_affinity 01 10
events{
     worker_connections 128;
}
worker_processor 4;
worker_priority 0;
worker_cpu_affinity 0001 0010 0100 1000
events{
     worker_connections 1024;
}
worker_processor 8;
worker_priority 0;
events{
     worker_connections 8192;
}











No comments:

Post a Comment