Original address: https://www.cnblogs.com/shitoufengkuang/p/4910333.html
First, preface
1, NIGNX version: 1.7.11 or more
2, Nginx uses an asynchronous, event-driven method to handle the connection. This approach eliminates the need to create additional dedicated processes or threads for each request, like a server with a traditional architecture, but instead processes multiple connections and requests in a worker process.
3, Nginx working in the non-blocking socket mode, and the use of epoll and kqueue such an effective method.
4, Nginx can be very good to handle the millions scale of concurrent requests.
5, blocking operation can destroy Nginx performance, we must at all costs to avoid the use of blocking.
6, even in the current official Nginx code, still unable to avoid the use of blocking in all scenarios, the thread pool mechanism implemented in NGINX1.7.11 solves this problem
Second, the question
1. Normally, Nginx is an event handler, a controller that receives all the connection events from the kernel and then sends instructions to the operating system.
2. The so-called "blocking operation" means any operation that causes the event processing cycle to stop significantly for a period of time
3, operation can become blocking operation for various reasons
Third, thread pool
1, to Nginx, the thread pool is the function of the distribution service . It consists of a task queue and a set of threads that handle this queue.
2 . When a worker process needs to perform a potentially long operation, the worker process does not perform this operation on its own, but instead puts the task into the thread pool queue, and any idle thread can fetch and perform this task from the queue.
3, the disk reading speed can not be faster than the disk to produce data.
4. The "read from disk" operation is typically the most common example of blocking operations, but in practice, the thread pool implemented in Nginx can be used to handle any tasks that do not fit in the main loop.
5. The two basic operations performed in a thread pool are read () system calls in most operating systems and Sendfile () in Linux.
Nginx Learning Note (vi) Improved 9 times-fold increase in thread pool performance