This isn't nginx versus apache. I'm interested in the architectural benefits of NGinx over Apache. When I could understand -

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

Why? Where does Apache get behind?

There's not one reason nginx strictly "outperforms" Apache. For a lot of load designs you might configure Apache to ensure that it handles this load. For many (very busy) load designs nginx in arrears configuration can exhibit performance degradations, and may require fine tuning to operate right.

However, it's been the expertise of many, that nginx really works "better" as they are, or with simple tuning. Many systems' performance clearly enhanced when nginx was installed like a front-finish, with Apache gone to live in back finish.

The main reason is the fact that nginx is event-driven, and consists of the condition machine which handles the lifecycle of connections. This way, you could have very couple of "worker" processes, each handling many 100s as well as 1000's of connections concurrently. For Apache you'll have to run exactly the same quantity of child processes (or threads) as the amount of connections.

It's apparent that three processes against a 1000 processes ought to be an enormous win, at minimum.

Particularly, nginx easily enables to help reduce the burden of serving static files (images, Javascript, CSS). Handling each additional connection in nginx is extremely cheap, in order the static files are generally a majority when it comes to quantity of demands, you receive efficient processing.

Also, nginx performance is much better for "slow clients". If you have Apache searching straight to the web, and clients send demands over (stuffed up) lines, your (fast) server will need to with patience feed the (slow) client, waiting until it consumes the whole response. Thus the Apache child (or thread) canrrrt do anything helpful. Nginx worker, however, simply keeps this slow connection in epoll group of descriptors, even while processing other connections.

In the conceptual perspective, it is best to attempt to separate the "classes" of demands, using their own performance profile and demands. E.g., serving small static files is just one of such classes serving dynamic pages is yet another such class serving huge static files is an additional. Presenting nginx for your system unconditionally handles this separation.