All Articles

Benchmarking a Web Server With Apache Bench

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 here, ab.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 command I’ll be using is below and will be testing with 100 total requests with a maximum of 10 concurrent requests.

ab -n 100 -c 10

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.

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, it’s being tested 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

As I’m migrating posts across to my new site, I should add that this was written 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 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