Performance of Apache 2.4 with the event MPM compared to Nginx


I wrote a little while ago about how, for running PHP, Nginx was not faster than Apache.  At first I figured that it would be and then it turned out not to be, though only by a bit.

But since Apache also has an event-based MPM I wanted to see if the opposite results were true; that if Apache were using its event MPM it would be about the same as Nginx.  I had heard that Apache 2.2’s event MPM wasn’t great (it was experimental) but that 2.4 was better, possibly even faster, than Nginx.

So I had a few spare moments this Friday and figured I would try it out.   I basically ran ab at concurrency levels of 1, 10, 25, 50, 100 and 1000.  Like before the results surprised me.



The first run with Nginx was impressive.  It peaked at 14,000 requests per second.  Given my wimpy VM that  I ran it on, those numbers are pretty good.  What surprised me was that Apache was only half that.  I will say for the record that I do not know how to tune the event MPM.  But I don’t really have to tune Nginx to get 14k requests per second so I was expecting a little better from Apache.  So I pulled out all of the LoadModule statements I could but still have a functional implementation of Apache.  While the numbers were 25% better or so they were still well shy of what Nginx was capable of.  Then I added the prefork MPM to provide a baseline.  Again, I was surprised.  The event MPM was faster than the prefork MPM for static content, but not by much.

So it seems that if you are serving static content Nginx is still your best bet.  If you are serving static content from a CDN or have a load balancer in front of Apache which is running PHP then the prefork MPM is the way to go.  While the event MPM will help with concurrency it will not help you speed up PHP and so is not really needed.

13 thoughts on “Performance of Apache 2.4 with the event MPM compared to Nginx

  1. I guess it’s time for you to run a benchmark with a “true” PHP application behind it 🙂
    And let us know what version of nginx you’re using… I’m using mostly 1.4.3 and 1.4.7 (I have no idea if there are substantial performance issues between them, the changelogs show mainly bug fixes and security patches)

  2. Gwyneth Llewelyn A “true” PHP application would actually make the results a little more murky because the test would likely involve more logic to be executed.  And, largely (though there might be some circumstances that might negate this), once you are in PHP, the web server doesn’t matter much.  As such the true performance difference would be minimized.  The actual performance difference between the two, once a true PHP application is executed, is negligible and the performance benefit from Nginx largely comes from dishing out static content.

  3. BrianLayman Yep, it does show that Nginx is faster than Apache.  I was hoping that Apache’s Event MPM would bring Apache close.  In the end it doesn’t.  The “faster” that I referred to was that Nginx has been reported to be faster than Apache and is, therefore, always a better choice.  My quick test was the previous blog post that I referenced which showed that, when running PHP (that’s key), the Apache prefork MPM is faster.  Just a smidge, but faster.  That benefit goes away, however, once static content is included at which point Nginx is faster.

  4. kschroeder Good point… and the benchmark would actually only reveal performance data for that single application, and not others. So I guess you’re right, you did your benchmark well.

  5. I have for the past week or so been setting up an Load Balancing environment and have tried quite a few combo’s, I have tried Varnish with a Nginx and apache Backend. Haproxy with a Nginx and Apache backend. A Nginx with a Nginx backend and now my final setup and a Nginx Load balancer with apache2 running MPM event and php-fpm and its loads faster than any of the other combos. my question is going to be one the backend servers start getting load how they are going to hold up LOL

  6. So that’s an Apache loaded with unnecessary modules (default config), directives, scanning and loading changes to .htaccess files and loads of features which Nginx will never have for years to come vs Nginx.

    I just benchmarked the 2 (nginx 1.6). The problem is Nginx is designed for benchmarks. If you tune Apache for benchmarks, it’ll outperform Nginx and it did in my case.

Leave a Reply

Your email address will not be published. Required fields are marked *