In this article let us discuss the Nginx(pronunced as engine-x) web server. From late 95’s Apache is the prominent web server in the web industry and most of the websites are using till today. We will see that is the bottleneck with Apache on heavy load with high concurrency. The latest Apache uses either pre fork method or worker multi-process mode (MPM). In both the cases when the client sends request the Apache will create additional processes/threads to process the request. When a process or thread gets spawned, there is a load on the hardware where it utilizes the CPU and RAM. During the heavier loads the resources availability will get drained and hence Apache won’t accept any new requests/the processing of requests will get slows down.
Nginx says it addresses the C10K problem which is highlighted in the paper. Unlike other web servers Nginx doesn’t use more processes and threads to handle the requests. Nginx adopted the “event-driven and asynchronous” architecture. Nginx won’t create new processes for each web request, instead it will create worker processes for the main Nginx process. Each of these processes is single-threaded. Each worker can handle thousands of concurrent connections. It does this asynchronously with one thread, rather than using multi-threaded programming. The below simple diagram depicts the way Nginx processes the client requests with minimal usage of system resources.
Nginx addresses the high scalability and high concurrency problem hence most of the high traffic sites are using. For example Netflix, Hulu, Pinterest, Airbnb, WordPress.com, GitHub, SoundCloud, Zynga, Eventbrite, Zappos etc…
In the coming articles will see how we can configure Nginx as load balancer. Until then, Happy Learning !!!