NGINX Versus APACHE Round 1

Before any of you read this, keep in mind that I am not a sys admin. I can do server stuff, but I build websites. I dont consider myself an authority on this subject, nor do I expect you to treat this as gospel.

I am going to be moving Skylines Australia to a faster (and cheaper) server shortly. I’ve been doing a lot of research into possible ways I can make the site run quicker and one of the areas of interest for me has been the possibility of using NGINX with PHP FPM and XCache for a more swift browsing experience. As I knew know very little about NGINX and reading a lot of conflicting information about using it, I thought I’d do some tests.

The test was simple and has been labelled Round 1 as I ran out of time.

I spun up an 8GB memory Centos 5.6 machine on Rackspace for the database, a 2GB memory machine for Apache and a 2GB memory machine for NGINX. 3 machines in total.

Apache and NGINX were installed with PHP but no caching and the database was read from the Database machine. This was to make sure that these web serving boxes could utilise the entire system themselves without having to compete with MySQL.

I then wrote a small script to load the site’s index page from my Macbook (pretty simple stuff);

(I’m aware that I could have reduced my code with functions and whatnot, it is just a quick and dirty script so I’m not too concerned about reusability.)

The results before installing any caching were already interesting and surprising.

APACHE BEST:
3.55
3.61
3.65
3.68
3.69
APACHE WORST:
6.33
5.22
4.04
3.96
3.73
APACHE AVERAGE: 4.146

NGINX BEST:
3.81
5.36
5.73
5.77
5.81
NGINX WORST:
6.28
6.16
6.03
5.93
5.84
NGINX AVERAGE: 5.672

So, surprisingly (for me, at least) Apache was quicker.

I then installed XCache and Memcached. I did very limited config with them both (which I have now lost, so can’t demonstrate.) and ran the script again.

APACHE BEST:
3.64
3.78
3.83
3.92
3.92
4.02
APACHE WORST:
5.8
5.35
5.25
5.24
4.02
3.92
APACHE AVERAGE: 4.475
NGINX BEST:
3.53
3.56
3.64
3.76
3.76
3.96
NGINX WORST:
6.53
6.18
6.12
5.95
3.96
3.76
NGINX AVERAGE: 4.699

So, while Apache’s average actually increased by .3 seconds, NGINX’s dropped by around 1 second. But, Apache was still quicker.

Now, this test is far from conclusive and the images from all servers have been saved to Cloud Files so when I get some time I’ll spin the same servers up and I am going to try and configure XCache and Memcached a little better and then run the script over 100 iterations to get a more definitive result. As it stands though, NGINX has given me no reason to consider switching from Apache.

If you have any ideas for more conclusive tests I can perform, I’d love to hear them. Keep in mind that I am testing my specific site so I dont want to be directed to other sites that have performed similar tests.

EDIT: See round 2.

  • I am definitely bookmarking this page and sharing it with my friends.

  • Is there a way I can tell my people about this post. 

  • I just wanted to say my thanks for the information provided here.

  • Compare Apache Prefork mod_php with Nginx PHP-FPM is not realist. Compare both PHP-FPM. I use Nginx because i have only 256 Mo RAM, and Prefork use process big memory footprint for pictures, and so very instable for extrems situations (DOS attack for example). Nginx PHP-FPM or Apache worker PHP-FPM split the server and the language, and you can have rules for static and rules for dynamic (for ex max 8 process for PHP and 250 for server). So, the memory footprint is low and server stable, DOS attack can quicky be killed. I have make more 10 hours tests with differents configuration, and i have finished to choise it. But change to Nginx, like all, has a cost.

  • Matteo

    At least you have tested the concurrences about PHP render .
    The php as module IMHO is faster than fcgi ( depending on infrastructure )
    Load static content from outside is stupid and not rappresent the reality .
    Let's try a "simple" test static+dynamic and count the seconds .
    Apache is a great peace of software but its perfomances on concurrent connections is not so spettacular .
    Whatever nginx got many other features that apache have too but not engineered as nginx.
    With our high load sites nginx solved many problems that apache cannot.

blog comments powered by Disqus