Nginx is a lightweight event-driven HTTP and reverse proxy server for Web, as well as mail server.
Apache: Thread/process oriented.
c10k Challenge?
Network services in the processing of tens of thousands of client connections, often appear inefficient or even complete paralysis, which is called c10k problem.
The most important feature of the c10k problem is that the design of the program is not good enough, the relationship between the performance and the connection number and machine performance is often non-linear. For example: If the c10k problem is not considered, a classic select-based program can handle 1000 concurrent throughput on the old server, and it will often not handle the throughput of concurrency 2000 on a new server with twice times performance. This is because the consumption of a large number of operations at the time of the policy is linearly correlated with the current number of connections N. The relationship between the resource consumption of a single task and the current number of connections will be O (n). While the service program needs to handle tens of thousands of sockets simultaneously I/O processing, the accumulated resource consumption will be considerable, which obviously will cause the system throughput can not match the machine performance. To solve this problem, you must change the policy that provides service to the connection.
Nginx Solution: Event-driven Architecture/single non-blocking Thread
Event-driven: What is it?
A simple example is:
1) Accept the request
2) triggering events in a process (event)
3) Process processing and return results
The biggest difference between Nginx and Apache is that the mechanism for dealing with transactions is different:
Apache works in a common way, each request will monopolize a worker thread, and when the number of concurrent numbers is thousands of, thousands of of the threads are processing the request. This is a big challenge for the operating system, the memory footprint of the thread is very large, the thread context switch brings a lot of CPU overhead, the natural performance will not go up.
Nginx uses an asynchronous, non-blocking event handling mechanism, which is mentioned later in the article.
Nginx (1): Introduction