How to Benchmark HTTP Latency With Wrk.

DevOps & Cloud Computing A-Z Guide.

Dec 7, 2018 · 4 min read


Wrk is a modern HTTP benchmarking tool capable of generating significant load when running on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.

An optional LuaJIT script can perform HTTP request generation, response processing, and custom reporting.

Wrk is useful for testing any website or application that relies on HTTP, such as:

  • Rails and other Ruby applications
  • Express and other JavaScript applications
  • PHP applications
  • Static websites running on web servers
  • Sites and applications behind load balancers like Nginx
  • Your caching layer

Tests can’t be compared to real users, but they should give you a good estimate of expected latency so you can better plan your infrastructure. Tests can also give you insight into your performance bottlenecks.

Step 1. Install Docker.

To make our lives easier we will use Docker, so we can start wrk inside a container. The saved time will be invested in learning wrk.

First, update the package lists:

$ sudo apt-get update

Install Wget and cURL:

$ sudo apt-get install -y wget curl

Download and install Docker:

$ sudo wget -qO- | sh

Add your user to the docker group so you can execute Docker commands without sudo:

$ sudo gpasswd -a ${USER} docker

$ sudo service docker restart

$ newgrp docker

To verify that docker is installed correctly use this command:

$ docker — version

You should see something like:
Docker version 18.09.0, build 4d60db4

Step 2. Install wrk.

Since we have Docker it’s very easy. Just download the williamyeh/wrk image from the Docker registry hub with this command:

$ docker pull williamyeh/wrk

The command above downloads a Docker image that contains wrk.

Step 3. Run a wrk Benchmark Test

Let’s see the options wrk has available for us. Running the wrk container with version flag for a brief summary of its usage:

$ docker run — rm williamyeh/wrk -v


Now that we have a good overview, let’s compose the command to run our test. Note that this command won’t do anything yet, since we’re not running it from inside the container.

The simplest case we could run with wrk is:

The simplest case we could run with wrk is:

wrk -t2 -c5 -d5s -H ‘Host:’ — timeout 2s

Which means:

  • -t2: Use two separate threads
  • -c5: Open six connections (the first client is zero)
  • -d5s: Run the test for five seconds
  • -H 'Host:': Pass a Host header
  • --timeout 2s: Define a two-second timeout
  • The target application

Let’s run the described example in our wrk Docker container:

$ docker run --rm williamyeh/wrk -t2 -c5 -d5s -H ‘Host:’ --timeout 2s

Wait a few seconds for the test to run, and look at the results, which we’ll analyze in the next step.

Step 4. Evaluate the Output


Current configuration summary:

The benchmark took 5 seconds and the test used two threads.

Normal distribution parameters for the latency and req/sec statistics:

This part shows us the normal distribution details for our benchmark — what parameters a Gaussian function would have.

Benchmarks don’t always have normal distributions, and that’s why these results might be misleading. Therefore always look at the Max and +/- Stdev values. If those values are high, then you can expect that your distribution might have a heavy tail.

Statistics about the request numbers, transferred data, and throughput:

Here we see that during the time of 5.07 seconds, wrk could do 151 requests and transfer 237,12KB of data. Combined with simple math (total number of requrests/benchmark duration) we get the result of 29.76 requests per second.

Summary. What results are best?

Your goal is to keep Requests/sec as high as possible and the Latency as low as possible.

Ideally, the latency shouldn’t be too high, at least for web pages. The limit for a page load time with assets is optimal when it’s around two seconds or less.

Thank you for reading!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade