Apache vs nginx {performance comparison}

Development / Uploaded by admin / March 2013

It’s nothing out of the ordinary for me to be researching new technologies and methodologies to implement in our team at Organic Development.

It recently came to my attention however, that an emerging server technology called nginx is reputedly overtaking Apache. Not only this, but this so called ‘nginx’ is more popular than Microsoft’s IIS solution.

Before last week I never heard of nginx, so I made it my mission to find out more and investigate the claims that nginx is faster than Apache….

What is NGINX?

Nginx is pronounced engine-x, and it is very much just a server engine that can do quite a few things. The wikipedia definition of nginx is:

In my setup I’ve got nginx setup as a replacement for Apache (web server) and I’ve replaced php with php-fpm, but I’ve still got mysql running.

The Challenge:

I’ve got a project I’m working on which has a mathematical calculation that originally took over 30 seconds to compute, without caching. I wanted to get this faster still, and after a few days hard coding, I got the time for the calculation down to 8 seconds. This was running on LAMP! (Apache and PHP 5.3.14)

If the rumours were true about nginx, then I could get that calculation running even faster – I had to try it out. The challenge has been set – make the calculation run even faster!

The Installation:

First of all I had to get nginx installed, which at first seemed to be a pain in the backside, simply because the tutorials available assumed certain local setups and requirements, none of which I had! So after hours of research, sheer brute force and a few whiskies later I managed to get nginx, mysql and php-fpm installed and configured via Brew on my Mac, 10.8.

The Tests:

The tests I ran comprised of the following:
Environment:
Processor  2.3 GHz Intel Core i7
Memory  8 GB 1600 MHz DDR3
Software  OS X 10.8.2 (12C2034)

Software:
Nginx setup:
NGINX 1.27
PHP 5.3.15
MySQL 5.6.12

Apache setup:
Apache 2.2.22
PHP 5.3.14
MySQL 5.5.25

Test Case:

Uncached load tests; 1 individual request, 10 simultaneous requests, 50 requests split into 25 simultaneous users.

For this test, the most complex calculation on my project was accessed, which processed 637 calculations involving 211 database rows per calculation and was testing using the apache benchmarking tool.

The Results:

The results were quite a contrast. Nginx powered ahead but my tests also showed some interesting statistics too:


As you can see, nginx offers a higher transfer rate compared to Apache, but also has less of a wait time between receiving the request and passing a response back.

I also noticed that nginx can handle more requests per second, and is able to ramp up as the load increases, however apache remained pretty static on this front.

The incredible statistic, for my limited machine I’ll give you that, was the drop off rate for pache, in that 7 out of 50 requests failed on the higher load test, whereas nginx powered ahead strong.

Although it would seem as though nginx reached a maximum on the transfer rate at the 10 concurrent users and then it looked like it hit a bottleneck on the ramp up to 25 users, further tests could see where this bottleneck gets hit, although it was a slight decrease whereas apache remained the same on the transfer rates throughout on average.

For some ratio figures:

As you can see, nginx wins every time, but what’s more important is that Apache actually hits a drop off rate with 25 concurrent users, where by per 25 users, 3-4 will lose connection.

Nginx can also handle on average 40% higher traffic than apache in 300% less time.
(Basically, it’s 4.2 times times as fast as Apache on these tests by average, and a lot more reliable!).

Conclusion:

I will undoubtedly be installing nginx on my servers in the cloud to improve performance on all our sites, it has proved itself through these simple benchmark tests to be a serious contended as a web server.

If you have any questions about the study explained, or would like to get in touch with your web server issues, I’d be most happy to chat.

Get in touch with the team at Organic on Twitter or Facebook or give us a call!

Comment on this article

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comments

  1. Bryson

    Why didn’t you use a common version of PHP and MySQL betwixt the two tests? The tests as they are have more than one variable (Apache/NGINX) and can’t be attributed to simply the webserver.

  2. Victor

    I want to start using nginx instead of Apache and your article was what I was looking for. Very helpful. Thank you!

  3. RedAlerT

    Thanks, very informative.

  4. Ted Wood, The Digital Orchard

    I’ve been using Nginx for years now, and it’s proven to be superior to and much easier to maintain than an equivalent Apache setup in my working situation. I develop and maintain several websites and a web applications framework and my Nginx-based servers perform much better than my Apache-based servers.

  5. nomadewolf

    yup, nice tests.
    but since the PHP and MySQL versions aren’t the same, the results MAY not be real indicatives of performance differences…

  6. Ira Chan

    Why don’t you push it over 10000 concurrent connections and see which one performs at lower CPU utilization. At 25 concurrent requests per second, even my dog can handle it faster than apache.

  7. zertux

    You are probably using the Apache prefork MPM, which is by default not that good for concurrency, you should have ran the test using the worker MPM or the event MPM (stable now).

    These results are not fair :)

  8. Toni

    Hi, thanks for the good article about Nginx! I like it too because it’s faster and a way more scalable than Apache. Once you have tried Nginx, you wont go Back to Apache :)