Apache 2.4 vs Nginx 1.4
12 May 2013Having setup Apache 2.4 and Nginx 1.4 I wanted to see how they performed. I am not trying to do a scientific performance test here, I am just interested in how Nginx behaves because I haven’t used it before.
I took a simple page with a table, some JavaScript and CSS in a separate file. I am running the tests using Apache JMeter.
Server | Samples | Average | Median | 90% line | min | max | error % | Throughput | KB/sec |
---|---|---|---|---|---|---|---|---|---|
apache | 1000 | 2 | 3 | 4 | 1 | 7 | 303 | 1122 | |
nginx | 1000 | 2 | 2 | 3 | 6 | 355 | 1301 | ||
apache | 10000 | 2 | 2 | 3 | 1 | 13 | 3013 | 11147 | |
nginx | 10000 | 2 | 3 | 4 | 1 | 8 | 2617 | 9571 | |
apache | 100000 | 20 | 14 | 30 | 1 | 441 | 4583 | 16952 | |
nginx | 100000 | 33 | 19 | 37 | 1805 | 2800 | 10239 | ||
apache | 1000000 | 211 | 194 | 238 | 1 | 7508 | 4629 | 17124 | |
nginx | 1000000 | 265 | 28 | 181 | 248243 | 0.05 | 2647 | 9678 | |
apache | 100000 | 596 | 37 | 704 | 31064 | 49 | 3035 | 7783 | |
nginx | 100000 | 575 | 3 | 144 | 32559 | 53 | 2823 | 6920 |
Looking at the results it seems that in the beginning there is no big difference. The difference starts with bigger numbers where Nginx shows higher average numbers because it fails to respond or responds very late in some cases. Although the average numbers are high because of the reasons managed you can see that most calls are handled faster.
Nginx is supposed to use less resources so I used the “uptime” command before starting the test and right after the test, here are the results (measured only for test: 1000 users, 1000 times):
Server | Average load before the test | Average load after the test |
---|---|---|
apache | 1,55, 0,33, 0,11 | 18,74, 9,97, 4,02 |
apache | 0,69, 0,16, 0,05 | 1,02, 0,77, 0,36 |
It clearly shows that Nginx uses less CPU than Apache for the same work, the difference is so big you can see it by just looking at the system monitor.
I like what I see from Nginx and I am definitely going to play more with it.