Apache vs nginx {performance comparison}

Development / 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:
Processor  2.3 GHz Intel Core i7
Memory  8 GB 1600 MHz DDR3
Software  OS X 10.8.2 (12C2034)

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!).


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!

Latest news