Nginx Vs Apache
Nginx Vs Apache
The need for serving large number of concurrent requests is raising every day. The prediction of C10K problem (i.e 10,000 concurrent clients) started the research on web server architecture which could solve this problem. As a result Nginx architecture was developed. This article explains on a very high-level how Nginx works to solve the scalability problem, along with high level differences between Nginx and Apache webserver.
the resources (memory, CPU) in hold. Also, creating separate processes consumes more resources. In Nginx, the solution to solve the above problem is to use Event-driven, asynchronous, non-blocking and single threaded architecture as shown in the diagram below.
By Single threaded it means that, multiple clients can be handled by a single worker process as the resources are not blocked. Nginx do not create a new process or thread for a new request. Here the worker process accepts the requests and process thousands of it with the implementation of highly efficient event loops. As shown in the above diagram, Nginx can be configured to have n number of worker process with a single master process over them. Thus nginx is able to do the same work with less memory as it is utilized in a very optimized way. If you are new to Nginx, get started by installing Nginx from source.
Nginx Vs Apache
As discussed above Nginx is based on event-driven architecture. Apache is based on process-driven architecture. It is interesting to note that Apache in its earliest release was not having multitasking architecture. Later Apache MPM (multi-processing module) was added to achieve this. Nginx doesnt create a new process for a new request. Apache creates a new process for each request. In Nginx, memory consumption is very low for serving static pages. But, Apaches nature of creating new process for each request increases the memory consumption. Several benchmarking results indicates that when compared to Apache, Nginx is extremely fast for serving static pages.
Nginx development started only in 2002. But Apache initial release was in 1995. In complex configurations situation, when compared to Nginx, Apache can be configured easily as it comes with lot of configuration features to cover wide range of requirements. When compared to Nginx, Apache has excellent documentation. In general, Nginx have less components to add more features. But Apache has tons of features and provides lot more functionality than Nginx. Nginx do not support Operating Systems like OpenVMS and IBMi. But Apache supports much wider range of Operating Systems. Since Nginx comes only with core features that are required for a web server, it is lightweight when compared too Apache. The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU.