Nginx notes -Nginx in the structure and process management using Linux semaphores

The first is the difference between the Apache and Nginx (just to mention the benefits of Nginx here)

Apache low performance processing request.

 

Apache: a process to handle a request, blocking;

Nginx: process a plurality of processing requests, non-blocking;

 

 

Nginx application scenarios

Nginx can only deal with static resources, dynamic resource will have a reverse proxy to the application server.

The following procedure is processing the request Nginx:

Nginx a little and features

Hot deployment, smooth upgrades and secondary development of open source, high-performance concurrent, scalable, non-blocking asynchronous event-driven model

 

Nginx is a multi-process architecture:

Main course Master Process management following several processes:

CM (Cacah Manager), CL (Cacah Loader), Worker Process (this in general as auto, will generate a configuration file based on the number of CPU cores themselves).

 

Master Process have process management capabilities, will hang up the process of pulling up, so if you want to change the source code extensions do not modify the Master Process as possible.

 

Cacah Loader is used to load the cache

Cacah Manager is used to manage cache

The local cache is being stored in the worker process inside. All children are using shared memory approach to communication.

 

The following is a Linux semaphore management mechanism.

The key is to kill Keywords:

A total of 64 instructions, to clarify the following several:

Kill -17 $ PID # Semaphore parent and child communication, the child hung up, will signal the parent process

Kill -3 $ PID # will dump down the operation of the application. Because it can run into the situation where all the threads of the output current

Kill -15 $ PID # ordinary Kill, the program exits, if stuck, can not kill the

Kill -9 $ PID # regardless of doing, blocking, running both kill

Kill -1 $ PID # reload the configuration file

 

Using the semaphore management Nginx

Is generally not recommended for direct worker process to manage, but the use of manager to manage

nignx event is bound, his worker child processes in general is that you have a few computers give you the number of cpu

There worker_processes nginx is usually auto detect themselves in the configuration file inside.

As follows:

Nginx is currently only one worker process, this is only because I am a cpu

You can modify the profile to change as follows:

4 change, and then reload the configuration file

There are two commands:

./nginx -reload
kill -1 xxxx

You can see:

There are four worker process up.

Here, if the source to be changed or other operations, are generally on the worker process threads.

Another is to help ./nginx -h

 

 

Released 1314 original articles · won praise 2609 · Views 1.85 million +

Guess you like

Origin blog.csdn.net/qq78442761/article/details/105116226