How does Nginx handle HTTP requests?

I understand the thread that Apache uses: every connection opens a thread and when a response is sent, the thread closes, freeing up resources for other threads).

But I am not getting an event driven project that uses Nginx. I read some basics about event driven design, but I don't understand how nginx uses it to handle web requests.

Where can I read and understand how Nginx handles connections in an event-driven way, so I understand why this is better, and not just accepting an event-based design, better than a thread-driven design.

+54
apache nginx
Aug 09 '10 at 1:23
source share
1 answer

Nginx uses the Reactor template. In principle, this is single-threaded (but can cause several processes to use multiple cores). The main event loop expects the OS to report a ready event - for example, this data is readable from the socket, after which it is read into the buffer and processed. A single thread can serve tens of thousands of simultaneous connections very efficiently (the thread model per connection may fail due to the huge costs of context switching, as well as a large amount of memory, since each thread needs its own stack).

+51
Aug 09 '10 at 2:19
source



All Articles