1

Im very confused right now...

I've always used Nginx to serve up static files and pass off php to Apache. I built a new box 4GB Ram, installed Apache 2.4.7 with mpm_prefork module and NginX 1.4.6. I setup what I needed to and decided to run some ab tests. I was shocked at what I saw. In every ab test Apache did just about as well as NginX.

Is this right for Apache 2.4? I've read about the performance upgrades with 2.4, however in the past NginX would destroy Apache. Am I missing something?

Apache:

Concurrency Level:      100
Time taken for tests:   1.157 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      279000 bytes
HTML transferred:       21000 bytes
Requests per second:    864.65 [#/sec] (mean)
Time per request:       115.654 [ms] (mean)
Time per request:       1.157 [ms] (mean, across all concurrent requests)
Transfer rate:          235.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       24   32  11.3     27     236
Processing:    27   78  15.6     77     380
Waiting:       26   78  15.6     77     379
Total:         55  109  21.1    104     404

Percentage of the requests served within a certain time (ms)
  50%    104
  66%    116
  75%    121
  80%    123
  90%    129
  95%    135
  98%    162
  99%    173
 100%    404 (longest request)

NginX:

Concurrency Level:      100
Time taken for tests:   1.026 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      362000 bytes
HTML transferred:       21000 bytes
Requests per second:    975.00 [#/sec] (mean)
Time per request:       102.564 [ms] (mean)
Time per request:       1.026 [ms] (mean, across all concurrent requests)
Transfer rate:          344.68 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       24   33  14.4     29     223
Processing:    24   34  39.2     28     664
Waiting:       24   34  39.2     28     664
Total:         50   67  42.2     57     691

Percentage of the requests served within a certain time (ms)
  50%     57
  66%     72
  75%     76
  80%     77
  90%     80
  95%     86
  98%     97
  99%    240
 100%    691 (longest request)

This is consistent across all my tests. This test has the biggest performance gap of all my test. Normally Apache is coming in about 5%-10% less in raw requests/sec of NginX.

If Apache 2.4 is in fact close to NginX then I don't see any point in setting up a reverse proxy and all the other complexity that comes with it.

Thoughts?

Eko3alpha
  • 147
  • 1
  • 8
  • Did you monitor server resource usage between your tests? The problem with Apache is that every request, even for static files, will use memory for the PHP module also. – Tero Kilkanen Apr 02 '15 at 13:49
  • 2
    I'm not saying you're wrong, but those are some tiny samples. You may want to rerun them for a) a longer amount of time than just a second and b) run them across a wide variety of pages, with GET, POST, query strings, and whatever other elements your site actually uses. – Hyppy Apr 02 '15 at 13:51

1 Answers1

1

In a test like this, I'd expect that Apache is keeping 100 child processes alive throughout the duration of the test once it starts them, so as a result it's able to achieve comparable performance to the event-driven-single-process model of Nginx. I bet you might even be able to close the benchmark gap further if you set StartServers and MinSpareServers to 100 for Apache. I'd expect the memory usage across all httpd processes to be higher though to achieve the same concurrency, which may or may not be much of a drawback depending on your available RAM and maximum expected concurrency.

sa289
  • 1,308
  • 2
  • 17
  • 42
  • This experiment has been interesting. I was expecting NginX to outperform Apache by a huge margin regardless of the resources available to Apache. After monitoring the resource usage it was clear that Apache's performance was coming at a great cost. It was using significantly more ram and spawned 125 processes just to keep up. However since we have plenty of ram at our disposal, I don't see any real benefit of adding NginX at this time, given that Apache can hold its own if enough ram is available. – Eko3alpha Apr 02 '15 at 16:11