Saturday, March 1, 2014

Apache and Nginx

I recently came across a blog  that says Nginx performance is better than Apache because, “Nginx doesn’t create a new process for a new request. Apache creates a new process for each request” This is not completely true, Apache MPM has two models, 1. Prefork (Above statement is applicable for this model) 2. Worker The worker MPM uses processes with many threads for each process. Each thread handles one connection at a time. This model is suitable for high performance web servers. I have not worked on Nginx and but managed high few high traffic website with Apache (Tuned) and lighthttpd quite well. I wanted to learn more about the performance advantage that Nginx has over Apache or lighthttpd. Is there any study/load testing done to prove Nginx could perform better than Apache (Tuned) for high traffic website? Please back your statement with data. (In Data we trust rest is ;)
In response to Event Driven Arch of Nginx

Agree Buddy :) Nginx is event driven and asynchronous from design perspective and I guess this very helpful for more requests that are long-running but of a small size (Example Mobile)
As ONESTONE says:
"Nginx uses the Reactor pattern. Basically, it's single-threaded (but can fork several processes to utilize multiple cores). The main event loop waits for the OS to signal a readiness event - e.g. that data is available to read from a socket, at which point it is read into a buffer and processed. The single thread can very efficiently serve tens of thousands of simultaneous connections (the thread-per-connection model would fail at this because of the huge context-switching overhead, as well as the large memory consumption, as each thread needs its own stack)"

But Apache has a fix around it- Event MPM (http://httpd.apache.org/docs/2.2/mod/event.html)
As I know this fix is experimental and has issue with https :(
But again as per Kevin, Apache could outrun Nginx when "you are running pure PHP content on a given server, Apache seems to still be the best bet for the job."

http://www.eschrade.com/page/why-is-fastcgi-w-nginx-so-much-faster-than-apache-w-mod_php/

I would design this in following way,

* CDN (CSS, JS and images)

* Run PHP from Apache (Tuned)

Again as I mentioned before I don't know Nginx (Never worked on it) so idea is to LEARN and EVOLVE. Leverage Nginx when required and possible.
I never carry any preconceived notion/baggage of dogma :) just a student of life/events :)

No comments:

Post a Comment