epoll only appeared after Linux 2.6, so Nginx uses the epoll model. Therefore, Nginx is very powerful when processing static files or doing reverse generation, because it is mainly IO operations.
epoll is an enhanced version of select/poll, which is based on event notification.
Apache and Tomcat, although they are also Web servers, they also play the role of application servers. The reason why they are called application servers is because they really need to run specific business applications, such as scientific computing, graphics and images, and database reading. Write etc. They are likely to be CPU-intensive services, and event-driven is not suitable.
You can’t have your cake and eat it too. Event-driven is suitable for IO-intensive services, and multi-process or thread is suitable for CPU-intensive services.
Furthermore, according to the characteristics of TCP and HTTP protocols, most servers will retain the persistent link of time_wait. Web servers are mainly used to process HTTP protocol requests.
Nginx is an implementation of asynchronous IO. It has a large eventloop, so no blocked processes are allowed, otherwise it will block everything. You should pay special attention to this when developing an nginx module. This also brings some Problems such as fully asynchronous IO will cause the program to be unreadable, so it may cause problems in later maintenance. This is when Lua comes~~
Let me tell you why not use the synchronous non-blocking model.
Since socket is a non-blocking method, the user thread returns immediately when it initiates an IO request. However, no data was read. The user thread needs to continuously initiate IO requests. Only after the data arrives, the data is actually read and execution continues.
The pseudocode for user threads using the synchronous non-blocking IO model is described as:
That is, the user needs to continuously call read to try to read the data in the socket, and then continue to process the received data until the reading is successful. During the entire IO request process, although the user thread can return immediately after each IO request is initiated, in order to wait for the data, it still needs to continuously poll and repeat requests, which consumes a lot of CPU resources. Therefore, this model is rarely used.
Why not use the asynchronous IO model? 1) Asynchrony needs to be implemented through a large number of callbacks and hook functions. Debugging, maintenance, and readability are all a big challenge. There is currently no good tool set to support asynchronous programming. 2) Blocking io+ threads and multiplexing have better solved the problem of high concurrency, and the cost is not high. 3) Asynchronous IO is not necessarily really asynchronous, such as POSIX AIO (glibc AIO), the performance is not good. For details, see Asynchronous IO Application
epoll only appeared after Linux 2.6, so Nginx uses the epoll model. Therefore, Nginx is very powerful when processing static files or doing reverse generation, because it is mainly IO operations.
epoll is an enhanced version of select/poll, which is based on event notification.
Apache and Tomcat, although they are also Web servers, they also play the role of application servers. The reason why they are called application servers is because they really need to run specific business applications, such as scientific computing, graphics and images, and database reading. Write etc. They are likely to be CPU-intensive services, and event-driven is not suitable.
You can’t have your cake and eat it too. Event-driven is suitable for IO-intensive services, and multi-process or thread is suitable for CPU-intensive services.
Furthermore, according to the characteristics of TCP and HTTP protocols, most servers will retain the persistent link of time_wait. Web servers are mainly used to process HTTP protocol requests.
There is no perfect one, only a more suitable one
Node is asynchronous io
And the performance is really good
Nginx is an implementation of asynchronous IO. It has a large eventloop, so no blocked processes are allowed, otherwise it will block everything. You should pay special attention to this when developing an nginx module. This also brings some Problems such as fully asynchronous IO will cause the program to be unreadable, so it may cause problems in later maintenance. This is when Lua comes~~
Let me tell you why not use the synchronous non-blocking model.
Since socket is a non-blocking method, the user thread returns immediately when it initiates an IO request. However, no data was read. The user thread needs to continuously initiate IO requests. Only after the data arrives, the data is actually read and execution continues.
The pseudocode for user threads using the synchronous non-blocking IO model is described as:
That is, the user needs to continuously call read to try to read the data in the socket, and then continue to process the received data until the reading is successful. During the entire IO request process, although the user thread can return immediately after each IO request is initiated, in order to wait for the data, it still needs to continuously poll and repeat requests, which consumes a lot of CPU resources. Therefore, this model is rarely used.
Why not use the asynchronous IO model?
1) Asynchrony needs to be implemented through a large number of callbacks and hook functions. Debugging, maintenance, and readability are all a big challenge. There is currently no good tool set to support asynchronous programming.
2) Blocking io+ threads and multiplexing have better solved the problem of high concurrency, and the cost is not high.
3) Asynchronous IO is not necessarily really asynchronous, such as POSIX AIO (glibc AIO), the performance is not good. For details, see Asynchronous IO Application