This is the 12th day of my participation in the August More Text Challenge. For details, see:August is more challenging
This article has been synchronized to the GitHub open source project: The Way of the Supergods in Java
The master and the worker
-
When Linux starts, there are two processes associated with Nginx, one for master and one for worker.
How The Master works
-
When the client sends a request to Nginx, the master will receive the request and notify all worker processes. At this time, the worker will compete for the request. After a worker grabs the request, it will forward the request according to the set steps.
-
Benefits of a master and multiple workers
- You can use
nginx -s reload
Hot deployment. When a hot deployment is performed, it is normalworker
It will restart, but the request is being processedworker
No, we won’t restart until the request is processed. - For each individual
worker
For concurrency, there is no need to consider locking. And eachworker
They don’t affect each other. Reduces the possibility of instantaneous service failure.
- You can use
The setting of the worker
The number of worker
- Like Redis, Nginx adopts IO multiplexing mechanism, and each worker is an independent process. each
worker
Is used to maximize CPU performance. - Therefore, it is most appropriate for the number of workers to be equal to the number of cpus on the server. (Set several workers for a few cores)
- Less Settings waste CPU performance, resulting in slower processing of service requests.
- Setting too many Settings will cause CPU loss due to frequent context switching.
This article has been synchronized to the GitHub open source project: The Path of The Java Supergods for more Java knowledge, please visit!