In a production environment, Nginx uses a master process to manage multiple worker processes. In general, the number of worker processes is the same as the number of CPU cores on the server. The worker process is responsible for providing services, while the master process is responsible for monitoring and managing the worker process. Worker processes realize load balancing and other functions through inter-process communication mechanisms such as shared memory and atomic operation.

Starting multiple processes simultaneously in master/worker mode has the following advantages:

  1. The master process focuses on management. When a serious error occurs in any worker process, the master process will immediately start a new worker process to achieve high availability.
  2. Multiple worker processes processing requests can make full use of SMP multi-core architecture, thus realizing multi-core concurrent processing in a true sense. When the number of processes on Nginx is equal to the number of CPU cores and each worker process is bound to a specific CPU core, interprocess switching can be minimized and high performance can be guaranteed.

Symmetric multi-processing (SMP) refers to the convergence of a group of processors (multiple cpus) on a computer, which share memory subsystems and bus structures. Compared with asymmetric multiprocessing, it is a widely used parallel technology.

You can run the cat command to view the number of cpus on the Linux server.

 cat /proc/cpuinfo|grep 'processor'
Copy the code

It can be seen that this server has three core cpus, Nginx default will build three worker processes (through ps – ef | grep Nginx command) :


Nginx can achieve high availability and high performance with the master/worker architecture