Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx and apache web servers [closed]

This question is not nginx vs apache. I am more interested in the architectural advantages of NGinx over Apache. As I was able to understand -

  • nginx is an asynchronous, event-driven, web-server which outperforms Apache by a huge margin.

Why is this? Where does Apache fall behind?

like image 388
Srikar Appalaraju Avatar asked Sep 03 '10 05:09

Srikar Appalaraju


People also ask

Is Apache web server still used?

After Tim Berners-Lee's CERN httpd and NCSA HTTPd in the first couple of years of the internet, Apache – first released in 1995 – quickly conquered the market and became the world's most popular web server. Nowadays, it still is in that market position but mostly for legacy reasons.

Does Nginx conflict with Apache?

Apache and Nginx can definitely run simultaneously. The default config will not allow them to start at the same time because they will both try to listen on the same port and the same IP.

Is Nginx a replacement for Apache?

In terms of performance, NGINX is much better than Apache. NGINX performs 2.5 times faster than Apache — and consumes less memory as well. However, Apache has more functionality and features. It is worth noting that it is possible to use both together.

Are Nginx and Apache same?

Apache is an open-source web server. Nginx is a web server. It is also used as a reverse proxy server which revices the request from client and send the request to proxy server.


1 Answers

There is no single reason why nginx strictly "outperforms" Apache. For many load patterns you may configure Apache so that it handles this load. For some (very busy) load patterns nginx in default configuration can exhibit performance degradations, and can require fine tuning to work right.

However, it has been the experience of many, that nginx actually works "better" out of the box, or with simple tuning. Many systems' performance clearly improved when nginx was installed as a front-end, with Apache moved to back end.

The primary reason is that nginx is event-driven, and contains the state machine which handles the lifecycle of connections. That way, you can have very few "worker" processes, each handling many hundreds or even thousands of connections simultaneously. For Apache you will have to run the same number of child processes (or threads) as the number of connections.

It is obvious that three processes against a thousand processes should be a huge win, at very least.

In particular, nginx easily allows to greatly reduce the load of serving static files (images, Javascript, CSS). Handling each additional connection in nginx is very cheap, so as the static files are usually a majority in terms of number of requests, you get efficient processing.

Also, nginx performance is better for "slow clients". When you have Apache looking straight to the Internet, and clients send requests over (congested) lines, your (fast) server will have to patiently feed the (slow) client, waiting until it consumes the entire response. Thus the Apache child (or thread) cannot do anything useful. Nginx worker, on the other hand, simply keeps this slow connection in epoll set of descriptors, all the while processing other connections.

From the conceptual point of view, you should always try to separate the "classes" of requests, with their own performance profile and demands. E.g., serving small static files is one of such classes; serving dynamic pages is another such class; serving huge static files is yet another. Introducing nginx to your system implicitly handles this separation.

like image 183
squadette Avatar answered Oct 20 '22 06:10

squadette