: This article mainly introduces [reading notes] to explore the nginx Architecture 1 _ process model. if you are interested in the PHP Tutorial, refer to it. Original article: http://tengine.taobao.org/book/chapter_02.html%20ngx
After nginx is started, the process background contains one master process and multiple worker processes.
(Terminal nginx command interaction with master)
The master process is used to manage the worker process inclusion
- Receive external signals
- Send signals to worker processes
- Monitor the running status of a worker process
- When the worker process exits (abnormal), it automatically restarts the new worker process.
The basic network events are handled in the worker process. Multiple worker processes are peer-to-peer. they compete for requests from clients, and each process is independent of each other. One request can only be processed in one worker process. one worker process cannot process requests from other processes.
Process
- Every worker process comes from the master process fork. in the master process, first establish the socket (listenfd) that requires listen, and then fork multiple worker processes.
- Listenfd of all worker processes becomes readable when new connections are made. to ensure that only one process processes process the connection, all worker processes obtain the accept_mutex before registering the listenfd read event.
- The process that grabbed the mutex lock registers the listenfd read event and calls accept in the Read event to accept the connection. when a worker process is connected by accept, it starts to read the request, parse the request, and process the request, after the data is generated, return it to the client before disconnecting.
Benefits of this process model
- For each worker process, no locks are required for independent processes, saving the overhead of the lock.
- Programming and problem searching are also convenient.
- The use of independent processes can ensure that they do not affect each other. after a process exits, other processes are still working and the service will not be interrupted. The master process will soon start a new worker process.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the [study notes] to explore the nginx Architecture 1 _ process model, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.