[Reading Notes] exploring nginx Architecture 1 _ Process model

Source: Internet
Author: User
: 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

  1. 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.
  2. 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.
  3. 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.

    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.