Home > Article > Operation and Maintenance > How Nginx handles HTTP requests
Nginx is a high-performance web server that can handle a large number of concurrent requests at the same time. It combines multi-process mechanism and asynchronous mechanism. The asynchronous mechanism uses an asynchronous non-blocking method.
(Recommended tutorial: nginx tutorial)
The following is an introduction to Nginx’s multi-threading mechanism and asynchronous non-blocking mechanism.
1. Multi-process mechanism
Whenever the server receives a client, there is a server master process (master process) that generates a child process (worker process) Come out and establish a connection with the client for interaction until the connection is disconnected, and the sub-process ends.
The advantage of using processes is that each process is independent of each other and does not require locking, which reduces the impact of using locks on performance and reduces programming complexity and development costs.
Secondly, using independent processes can prevent processes from affecting each other. If one process exits abnormally, other processes will work normally, and the master process will quickly start a new worker process to ensure that the service is not interrupted. will interrupt, minimizing risk.
Disadvantages:
The operating system generates a child process that requires memory copying and other operations, which will cause a certain overhead in terms of resources and time. When there are a large number of requests, system performance will decrease.
2. Asynchronous non-blocking mechanism
Each worker process uses asynchronous non-blocking mode and can handle multiple client requests.
When a working process receives a request from the client, it calls IO for processing. If the result cannot be obtained immediately, it will process other requests (that is, non-blocking); and the client does not need to wait during this period. In response, you can handle other things (that is, asynchronous).
When IO returns, this worker process will be notified; the process is notified and temporarily suspends the currently processed transaction to respond to the client request.
The above is the detailed content of How Nginx handles HTTP requests. For more information, please follow other related articles on the PHP Chinese website!