Benchmarking a Web Server With Apache Bench

by Bret
Published: Last Updated on 6 minutes read

Whilst getting the site up and running, I wanted to make sure that I could squeeze every bit of performance out of it as I could. Nobody likes a slow website and I didn’t want it to crumble under the pressure of the 3 (optimistic, I know) visitors so it’s time to look into caching and verifying how much of a difference it makes using Apache’s Benchmark tool, “ab”, or Apache Bench.

Getting Ready

To test these we’ll need to first download the benchmarking tool (Windows users can grab the Apache files from hereab.exe will be in the bin folder and the commands should be the same from there):

Debian/Ubuntu: sudo apt install apache2-utils

CentOS/Fedora: yum install httpd-tools

I’ll be doing all of my testing from a 1GB instance from Vultr (Affiliate Link) as I had leftover credit. The below command will stress-test with a total of 100 requests, with a maximum of 10 concurrent requests.

ab -n 100 -c 10

Apache Bench – Before Caching

Out of the traps, this is a single core VPS hosted in Las Vegas and the underlying web server is Litespeed so it’s already a little more capable than default Apache setups but I’m sure it can be improved on. Let’s see how it fairs first with a default WordPress install.

Time taken for tests: 17.275 second  
Complete requests: 100  
Failed requests: 0  
Total transferred: 1397900 bytes  
HTML transferred: 1338800 bytes  
Requests per second: 5.79 [#/sec] (mean)  
Time per request: 1727.460 [ms] (mean)  
Time per request: 172.746 [ms] (mean across all concurrent requests)  
Transfer rate: 79.03 [Kbytes/sec] received

I feel like something’s not entirely right with these numbers as it seems pretty low but it’s a single core host VM with shared CPU resources so I’ll give it the benefit of the doubt and keep everything the same for testing. The next step was to install the LSCache (Litespeed Cache) plugin for WordPress which seemed the logical choice given its reviews and the fact we’re running Litespeed under the hood. A quick Plugins -> Add New -> LSCache in the WP-admin area will get it installed nice and easily.

Apache Bench – After Caching

Leaving everything at default after activating the plugin yields the following results from Apache Benchmark:

Time taken for tests: 4.821 seconds  
Complete requests: 100  
Failed requests: 0  
Total transferred: 1407700 bytes  
HTML transferred: 1346200 bytes  
Requests per second: 20.74 [#/sec] (mean)  
Time per request: 482.067 [ms] (mean)  
Time per request: 48.207 [ms] (mean, across all concurrent requests)  
Transfer rate: 285.17 [Kbytes/sec] received

As you can see, we’ve jumped from 5.79 requests per second to 20.74 (a 358% increase!) on the back of installing LSCache with it’s default settings alone so after some more tweaking, we should be pretty good.

This is by no means the most scientific of tests. I’m testing from one VM with shared resources to another on the other side of the world and it’s super basic but it gives you a rough idea on how to benchmark using basic tools available on all platforms and shows that a little caching goes a long way!

Edit as of 14/08/2020

I’ve now migrated to a new website backend, so the original results are from earlier in 2020 whilst I was still using WordPress. I’m now using a much faster, static site generated by Gatsby! I spawned a quick server again and used the same Apache Bench command as above and saw the following which a fair chunk better and the real-world experience is much, much better!

Time taken for tests:   3.227 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      2965422 bytes
HTML transferred:       2874100 bytes
Requests per second:    30.99 [#/sec] (mean)
Time per request:       322.676 [ms] (mean)
Time per request:       32.268 [ms] (mean, across all concurrent requests)
Transfer rate:          897.47 [Kbytes/sec] received

Edit as of 12/12/2021

Another year has passed and another change of backend has taken place.. I’m now running Jekyll on top of Cloudflare Pages, so another benchmark seemed fitting! As you can see, there’s another bump in performance so things are looking good. I’ll no doubt get bored and be posting another update here in 6-12 months after another change.

Time taken for tests:   3.016 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      1547968 bytes
HTML transferred:       1450900 bytes
Requests per second:    33.15 [#/sec] (mean)
Time per request:       301.650 [ms] (mean)
Time per request:       30.165 [ms] (mean, across all concurrent requests)
Transfer rate:          501.14 [Kbytes/sec] received

If benchmarking is your thing, my extensive testing on the Raspberry Pi Zero W & W2 is available now. Are any of you running websites on a Raspberry Pi?

You may also like...

Leave a Comment