[Nginx] nginx infrastructure

Source: Internet
Author: User

I. nginx Architecture Design

1) Excellent Modular Design

2) event-driven architecture

The event-driven architecture refers to the event generation from some event sources, where one or more event collectors collect and distribute events. Then, many event processors register events of interest to them, these events are also consumed.

For nginx, events are generally generated by NICs and disks. The event module collects and distributes events, and all modules may be event consumers.

Nginx adopts a complete event-driven architecture to process services. For traditional Web servers, event-driven events are often limited to TCP link establishment and closure events. After a connection is established, all operations before it is closed are no longer event-driven, this will degrade to the batch processing mode for each operation in order, so that each request will always occupy system resources after the link is established, and resources will be released only when the connection is closed. Traditional Web servers usually use processes or threads as event consumers. When an event generated by a request is processed by this process, it is known that the Process resources will be occupied by this request at the end of processing the request.

Only Event collectors and distributors in nginx are eligible to use process resources. They call the event consumption module when distributing an event to use the currently occupied process resources.

3) multi-phase Asynchronous processing of requests

That is, the process of processing a request is divided into multiple stages according to the event trigger method. Each stage can be triggered by event collection and distributor.

Advantages :?

4) management process and multi-Working Process Design

Nginx adopts a master management process and multiple worker processes.

Advantages:

1. Utilize the concurrent processing capability of multi-core systems.

All worker processes in nginx are completely equal.

2. Server Load balancer

Multiple worker processes achieve Load Balancing through inter-process communication. When a request arrives, it is easier to be allocated to a worker process with a lighter load for processing.

3. The management process monitors the status of the working process and manages its behavior.

5) Memory Pool Design

Advantage: It combines multiple memory requests to the system into one operation, which greatly reduces the consumption of CPU resources and memory fragments, this improves the memory usage and the number of concurrent connections that can be processed by the system.

2. Core Structure ngx_cycle_t in the nginx framework

1) ngx_listening_t struct

The ngx_cycle_t object has a dynamic array member listening. Each of its array elements is the ngx_listening_t struct. Each ngx_listening_t struct represents a port listened to by nginx.

2) ngx_cycle_t struct

3) ngx_cycle_t supported Methods

Iii. process the framework when nginx is started

4. Worker Process Workflow

V. Master process workflow

 

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.