Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of master and worker in nginx

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the role of master and worker in nginx". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of master and worker in nginx"?

Record collation:

After ① nginx starts, there is one master process and multiple worker processes. The master process is mainly used to manage the worker process, including: receiving the signal, sending the signal to the worker process, monitoring the working status of the worker process, and starting a new worker process when the worker process exits (abnormal). Basic network events are handed over to the worker process. Multiple worker processes are peer-to-peer, they compete equally for requests from the client, and the processes are independent of each other. A request can only be processed in one worker process, and it is impossible for a worker process to process requests from other processes. The number of worker processes can be set, which is generally consistent with the number of cpu cores of the machine. The reason is inseparable from the process model and event handling model of nginx.

When ② executes. / nginx-s reload, master reloads the configuration file, then starts a new process, uses the new worker process to accept requests, and notifies the old worker process to stop receiving requests, the old worker process will not accept the new one, and the old worker process will exit after processing the current request.

The ③ worker process processes users' requests: first, master generates a socket that listens to the corresponding port according to the configuration file, and then faster out multiple worker processes, so that each worker can accept messages from socket (in fact, every worker should have a socket at this time, but the addresses of these socket listeners are the same). When a connection comes over, each worker can receive a notification, but only one worker can establish a relationship with the connection, and the other worker will fail. This is the so-called shock group. Now, in order to solve this problem, nginx provides a shared lock accept_mutex, and with this shared lock, only one worker will receive the connection. When a worker process begins to read the request, parse the request, process the request, generate data, return it to the client, and finally disconnect the connection after the accept connection, such a complete request is like this.

Thank you for your reading, the above is the content of "what is the role of master and worker in nginx". After the study of this article, I believe you have a deeper understanding of the role of master and worker in nginx. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report