HAProxy Versus Apache Performance

After setting up HAProxy, I was curious how much performance was degraded by introducing an extra hop.

The Test

As with my last test, this was not meant to be scientific. I used ApacheBench again, sending 10,000 total requests and modifying the concurrency until I started getting broken responses.

I also put my site into maintenance mode so I would only be testing a static page and not introducing any database calls.

Apache Standalone Results

150 concurrent requests was about where my site could consistently serve up the maintenance page.

$ ab -n 10000 -c 150 http://www.christopherbaek.com/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.christopherbaek.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.7
Server Hostname:        www.christopherbaek.com
Server Port:            80

Document Path:          /
Document Length:        771 bytes

Concurrency Level:      150
Time taken for tests:   39.216 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      10710000 bytes
HTML transferred:       7710000 bytes
Requests per second:    255.00 [#/sec] (mean)
Time per request:       588.243 [ms] (mean)
Time per request:       3.922 [ms] (mean, across all concurrent requests)
Transfer rate:          266.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       78  371 1115.1     89   10300
Processing:    79  148 111.6     91    1227
Waiting:       79  148 111.6     91    1227
Total:        160  519 1114.8    185   10387

Percentage of the requests served within a certain time (ms)
  50%    185
  66%    415
  75%    450
  80%    714
  90%    743
  95%    990
  98%   5526
  99%   5561
 100%  10387 (longest request)
$ ab -n 10000 -c 160 http://www.christopherbaek.com/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.christopherbaek.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
apr_socket_recv: Operation timed out (60)
Total of 9852 requests completed

HAProxy And Apache Results

Pretty surprisingly, the number of concurrent requests my site could maintain dropped by 50% to 75!

$ ab -n 10000 -c 75 http://www.christopherbaek.com/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.christopherbaek.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.7
Server Hostname:        www.christopherbaek.com
Server Port:            80

Document Path:          /
Document Length:        771 bytes

Concurrency Level:      75
Time taken for tests:   49.783 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      10710000 bytes
HTML transferred:       7710000 bytes
Requests per second:    200.87 [#/sec] (mean)
Time per request:       373.370 [ms] (mean)
Time per request:       4.978 [ms] (mean, across all concurrent requests)
Transfer rate:          210.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       76  260 759.9     87   11087
Processing:    78  101  53.5     88     960
Waiting:       77  101  53.5     88     960
Total:        160  360 761.8    175   11175

Percentage of the requests served within a certain time (ms)
  50%    175
  66%    179
  75%    184
  80%    379
  90%    642
  95%    656
  98%   4111
  99%   4185
 100%  11175 (longest request)
$ ab -n 10000 -c 85 http://www.christopherbaek.com/
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.christopherbaek.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
apr_socket_recv: Operation timed out (60)
Total of 7691 requests completed

Conclusion

I was pretty surprised how much the performance dropped. Maybe this is why a lot of people use nginx as a proxy instead of HAProxy… Although this was some good information to discover, the database is still probably the bottleneck, so this shouldn’t become a problem anytime soon.