Ultimate Guide to Load Testing with WRK Tool

Md. Abu SalmanMd. Abu Salman
5 min read

Introduction

In the fast-paced world of software development, ensuring that your applications can handle the expected load is paramount. Enter load testing, a crucial practice that simulates real-world user behavior to evaluate how an application performs under various conditions. Load testing helps identify performance bottlenecks, assess system scalability, and ultimately, deliver a smoother user experience.

One of the go-to tools for conducting load tests on HTTP services is WRK. This open-source tool has gained popularity for its simplicity, flexibility, and robustness in measuring web server performance. Whether you're a seasoned developer or just dipping your toes into the world of load testing, WRK provides a powerful set of features to analyze and optimize your web applications.

In this blog post, we'll embark on a journey to explore the fundamentals of load testing and dive into the capabilities of WRK. From installation to running tests and interpreting results, we'll cover everything you need to know to get started with load testing using WRK. So, buckle up and let's dive into the exciting realm of performance testing!

Installation and Setup

Provide detailed instructions on how to install and set up WRK on different operating systems (e.g. macOS, Linux). Include any prerequisites and dependencies that users need to install beforehand.

Prerequisites

Git: WRK's source code is hosted on GitHub, so you'll need Git installed to clone the repository. Git can be installed using your operating system's package manager or downloaded from the official Git website.

you can find the project here https://github.com/wg/wrk.

Install

Mac

brew install wrk

Ubuntu

sudo apt-get install build-essential libssl-dev git -y git clone

https://github.com/wg/wrk.git wrk

cd wrk

sudo make

# move the executable to somewhere in your PATH, ex:

sudo cp wrk /usr/local/bin

Before running the wrk load testing, I created a simple web application using express.js. You can either create any web application server, or your existing web application server will be tested on wrk.

Here is my sample of node js application code base

// Import required modules
const express = require('express');

// Create an Express application
const app = express();
const port = 3000;

// Define a route handler for the root path
app.get('/', (req, res) => {
  res.send('Hello, World!');
});

// Start the server
app.listen(port, () => {
  console.log(`Server is running at http://localhost:${port}`);
});

I run this express project using node app.js

salman@salman:~/Desktop/load testing$ node app.js

Server is running at http://localhost:3000

Benchmark an HTTP endpoint

wrk -t12 -c400 -d30s --latency http://localhost:3000

  1. wrk: This is the command-line interface for WRK, the load testing tool we're using.

  2. -t12: This parameter specifies the number of threads to use during the test. In this case, -t12 means that WRK will use 12 threads to send requests concurrently. Each thread simulates a separate client making requests to the server.

  3. -c400: This parameter sets the number of connections to keep open simultaneously. With -c400, WRK will maintain 400 concurrent connections to the server throughout the test. Each connection represents a virtual user interacting with the server.

  4. -d30s: This parameter determines the duration of the test. -d30s means that the test will run for 30 seconds. During this time, WRK will continuously send requests to the server according to the specified parameters.

  5. --latency: This flag instructs WRK to collect and report latency statistics during the test. Latency measures the time it takes for a request to be sent to the server and for the corresponding response to be received. Including this flag allows you to monitor the distribution of response times, helping you understand the performance characteristics of your server under load.

  6. http://localhost:3000: This is the target URL of the server you want to test. Replace http://localhost:3000 with the actual URL of your server. WRK will send HTTP requests to this URL during the test to simulate user traffic and measure server performance.

Its took 30 second to generate the report

after 30 second you will see this result

  1. Indicates that a total of 139,100 requests were made during the 30-second test duration, resulting in 31.84 megabytes of data read from the server.

  2. Running 30s test @ http://localhost:3000:

    • This line indicates that the test ran for 30 seconds and targeted the server located at http://localhost:3000.
  3. 12 threads and 400 connections:

    • WRK utilized 12 threads and maintained 400 connections to simulate concurrent users interacting with the server.
  4. Thread Stats:

    • Avg: The average values for latency and requests per second across all threads.

    • Stdev: The standard deviation of latency and requests per second across all threads.

    • Max: The maximum observed values for latency and requests per second across all threads.

    • +/- Stdev: The percentage of samples falling within one standard deviation of the mean.

  5. Latency Distribution:

    • Shows the distribution of latency (response time) for different percentiles of requests:

      • 50%: 50th percentile (median) latency.

      • 75%: 75th percentile latency.

      • 90%: 90th percentile latency.

      • 99%: 99th percentile latency.

    • For example, 99% of requests had a latency of 157.30 milliseconds or less.

  6. 139100 requests in 30.05s, 31.84MB read:

  7. Requests/sec:

    • Average number of requests processed per second during the test. In this case, it's approximately 4628.86 requests per second.
  8. Transfer/sec:

    • Average data transfer rate from the server during the test, measured in megabytes per second. Here, it's approximately 1.06 megabytes per second.
0
Subscribe to my newsletter

Read articles from Md. Abu Salman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Md. Abu Salman
Md. Abu Salman