
Nginx vs. Apache in AWS - ruggerotonelli
http://blog.celingest.com/en/2013/02/25/nginx-vs-apache-in-aws/
======
colmmacc
Disclaimer: I work at AWS, I'm not speaking for my employer. I also helped
write Apache httpd, and I'm not speaking for Apache either. Just on my own
behalf.

The Apache configuration in the benchmark isn't great, using values of;

    
    
      MaxClients         400
      MinSpareThreads     25
      MaxSpareThreads     75 
      ThreadsPerChild     25
    

means that Apache will be doing extra work to spin up and spin down threads in
response to the load. It's best to keep everything static, e.g.

    
    
      MaxClients         1000
      MinSpareThreads    1000
      MaxSpareThreads    1000 
      ThreadsPerChild      25
    

That way there aren't additional clone() calls when under load (when you least
need it), the maximum concurrency is the same. For a fairer fight still, the
event mpm could be used.

Apache has nearly 20 year old configuration defaults - because it's best not
to break things on users who rely on them. Properly configured, and sanely
built, Apache can easily perform as well as nginx or lighttpd. These days 99%
of web-server performance is in the kernel and the SSL/TLS libraries. The
user-space code is almost completely irrelevant (and those configuration knobs
I mentioned really just control how often certain system calls are called).

But it hardly matters; "apt-get install nginx" just works, and you really
don't have to worry about it; you get a relatively small binary with some sane
defaults. Apache is awesome, but I run nginx on my own EC2 micro instance.
It's less hassle.

~~~
linuxsec
"Apache is awesome, but I run nginx on my own EC2 micro instance. It's less
hassle."

...enough said!

------
ck2
If you are going to test Apache at least use 2.4 in MPM-event mode so you are
testing apples to apples.

Using Apache 2.2 in worker mode is like comparing 8 year old tech to modern
code.

hint: Apache is still about 15-20% slower than nginx even in it's fastest mpm-
event mode, but it has many more years of features and modules available - it
all depends what your needs are - single site services vs multi-site
webhosting

You can always do the best of both worlds by proxying apache with nginx if you
need both. Takes one evening to figure out.

~~~
niggler
It's fair insofar as Debian still ships with 2.2 (2.4 in experimental)

~~~
INTPenis
I wouldn't call Debian Sta(b)le fair testing. Ubuntu is a slightly better but
to be truly fair you should use the latest stable production branch of each
program. Or dev if that's what you're testing.

~~~
niggler
The parent argued that the comparison is unfair, but those are the versions
you would get from Debian (apt-get install nginx-light apache2)

~~~
j-kidd
Well, the title is "Nginx Vs Apache in AWS", not "Nginx from apt-get Vs Apache
from apt-get in AWS". If you can't install the latest stable releases, then
don't write a comparison about them.

~~~
niggler
I don't know what versions are provided by the "amazon Linux AMI" (which the
article cites as the image) but I would venture to guess that those are
probably the standard (which would make the title apt)

~~~
morgo
Both are available in the Amazon Linux AMI:

httpd.x86_64 : Apache HTTP Server

httpd24.x86_64 : Apache HTTP Server

~~~
Vidart
Btw, there is also specially tuned Nginx AMI:
<https://aws.amazon.com/marketplace/pp/B00A04GAG4/>

------
peterwwillis
_"Here is a benchmark that shows the performance of a watermelon and a large
canteloupe lobbed from a trebuchet using different kinds of wood and rope
under different wind conditions. We tied random weights to each melon for no
apparent reason."_

What the fuck is the point of a performance benchmark if you didn't _tune any
settings for performance_?

~~~
emn13
Indeed - this doesn't tell you anything. Was nginx configured well? Was
apache? How much difference would it have made? Is the old apache version
relevant? Pointless test, unless you intend to use those settings on that
software on similar hardware.

~~~
peterwwillis
Hell, it would have been great if they had used a real closed testbed on a
local network instead of AWS. That would give you reproducible test results
that aren't influenced by things like communal server resources and a communal
network.

Regardless, they put zero thought into what makes each application work to its
peak performance and just picked two random configurations, probably based on
defaults that we know to be poor on Apache and advantageous on nginx. Using
worker instead of event just adds insult to injury.

~~~
taligent
Call me stupid.

But maybe Apache shouldn't ship defaults that have poor performance ?

~~~
peterwwillis
Well stupid, Apache ships with the default settings it does for historical
expectations of its users. But the application's tuning is driven largely by
how you use it, as there are several workers for Apache that all are useful in
different situations and require vastly different configuration options. This
is to say nothing of the kernel options which also need to be tuned to the
application.

The defaults are just defaults. They need to be changed to improve
performance.

------
arooaroo
I'm sure there's a good reason why Apache 2.4 wasn't in the comparison but the
author failed to mention it. Apache 2.2.23 may be a recent release but it's a
security update of an old but stable branch. Apache 2.4 branch is a year old
and a significant update including performance improvements to complete with
the likes of nginx.

I would still expect nginx to "win" but seems a fairer comparison somehow.

------
lemcoe9
Why exactly did they limit nginx to one worker proces?

~~~
machbio
I came here to write the same thing..

Worker Process 1; \- for nginx on 2 cores

Nginx Php ???? \- you have not mentioned what PHP config you are running on
Nginx

The Benchmarking needs to get better, this thing keeps on happening

------
gingerlime
I think one of the less obvious conclusions here is how important caching is
for wordpress, both with nginx and apache. I wish this test also covered W3
Total Cache though. I know it's hard to test all possible permutations.

One of the biggest issues with wordpress in particular however, is that whilst
it can run with nginx happily, it is written primarily with Apache in mind.
And many plugins rely on it too. I got it to work fine with nginx, but it
somehow still felt rather experimental. Perhaps it's just me.

I wrote a similar post from a slightly different angle, comparing the
cost/benefit of adding different caching layers. This included W3TC and
varnish on both apache and nginx, and using a cheap shared hosting.
<http://blog.gingerlime.com/2012/how-much-cache-is-too-much/>

------
karavelov
Even with one process/worker, so without any parallelism, nginx is faster than
apache most of the time. If you want to make a meaningful comparison you
should set the workers to the number of CPUs the OS sees (hyperthreaded or
not).

------
philtar
Can someone explain how the medium instance is serving more req/sec than the
large one when caching is on?

------
Nikkau
"Moreover… Nginx wasn’t always the winnner." is my favorite part.

------
nthitz
Good research and writeup.. But 3D bargraphs... Come on!

------
moe
It's posts like this making it to the frontpage (and the inevitable comment
thread) that make me sad about what HN has become.

What happened to the idea of making submissions (and comments) cost karma
points anyway?

~~~
peterwwillis
Whiny comments like this make me sad, but luckily I know they don't reflect on
the community as a whole.

------
manoleet
Lighttpd is missing... but good benchmark anyway.

~~~
nodesocket
I actually really like the lighttpd config structure, but its not actively
maintained and doesn't have the amazing community that nginx has. It is clear
that nginx has won the high performance web-server battle..

~~~
raylu
The sensible config syntax is the reason I still use lighttpd.
<http://wiki.nginx.org/IfIsEvil>

------
linuxsec
Nginx rulez... end of story!

