The relationship between Nginx processes in operation

Source: Internet
Author: User

In the context of formally providing the product, deploying Nginx uses the master process to manage multiple worker processes.

In general, worker processes are equal to the number of cores on the server, and each worker process is busy, and they truly provide Internet services.

The master process is very quiet and is only responsible for monitoring the worker process.

Load balancing between worker processes through shared memory, atomic operations, and a series of communication between processes

Shared memory: Shared memory is the mapping of memory that can be accessed by other processes, which is created by a process, but can be accessed by multiple processes. Shared memory is the fastest IPC approach and is specifically designed for low-efficiency operation of other interprocess communication modes. It is often used with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.

The relationship between nginx processes after deployment, as shown in:

So why do you configure multiple processes in Master-worker mode: two points

1.master processes can be unique, focusing only on managing worker processes that actually provide services

2. Multiple worker processes improve the robustness of the service and leverage existing SMP architectures (heap into multi-processing architectures) for true multicore concurrency processing

So why the worker process is designed to match the number of CPU cores, let's see what the difference between Apache and Nginx is:

Apache a process processing a request, in the case of large concurrency, can only increase the number of processes or threads, usually a server hundreds of processes, a large number of process switching resulting in unnecessary system resource consumption

Nginx A worker process can handle the number of requests only limited to the size of the memory, different worker process processing concurrent requests do not have a synchronization lock limit, the worker process does not sleep, so set the worker process is consistent with the CPU number of cores, the cost of switching between processes is minimal. (that is, the CPU is a 8-core, and the worker process is set to 8.) (Supplemental Knowledge: the relationship between process and CPU scheduling, when a single core processes multiple processes, is queued, so the number of worker processes is set beyond the core number is not significant, resulting in inter-process switching overhead)

The relationship between Nginx processes in operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.