Operations 5 min read

Mastering wrk: A Practical Guide to HTTP Load Testing with Lua Scripts

This guide introduces the wrk HTTP load‑testing tool, explains its multithreaded and Lua‑scriptable architecture, walks through installation and command‑line usage, interprets key performance metrics, and demonstrates how to extend functionality with custom Lua scripts for advanced testing scenarios.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Mastering wrk: A Practical Guide to HTTP Load Testing with Lua Scripts

Introduction

wrk is an HTTP load‑testing tool that features a multithreaded design with event‑notification systems (epoll, kqueue) for high concurrency and extensibility via Lua scripts for request generation, response handling, custom reports, etc.

Integrated multithreading and event notification (epoll, kqueue) to increase concurrency.

Extensible through Lua scripts for custom request generation, response processing, reporting, and more.

Usage Example

Installation

wrk runs on Linux or Mac .

Project repository: https://github.com/wg/wrk After cloning, build the project: make The build produces a wrk executable in the current directory.

Running

Execute a test command: ./wrk -t12 -c100 -d10s http://www.baidu.com This tests baidu.com with 12 threads, 100 concurrent connections, for 10 seconds.

It is recommended not to set the thread count excessively; a good rule of thumb is 2‑4 × the number of CPU cores.

Typical output includes:

Requests/sec

– basic metric indicating how many requests are processed per second. Thread Stats – per‑thread statistics such as latency, request rate, with Avg (average), Max (maximum), and Stdev (standard deviation). The standard deviation measures data dispersion; a larger Stdev across multiple runs suggests performance variability.

Combining Scripts

Lua scripts enable custom functionality such as sending POST data, custom aggregation after all requests, or testing multiple URLs.

Example post.lua script:

-- example HTTP POST script which demonstrates setting the
-- HTTP method, body, and adding a header

wrk.method = "POST"
wrk.body   = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"

Run wrk with the script using the -s flag:

./wrk -t12 -c100 -d10s --script=post.lua http://www.baidu.com

wrk provides several hook functions:

setup – called once per thread after all threads are created.

init – called before each request is sent.

delay – introduces a delay between requests.

request – allows modification of the request object before it is sent.

response – processes each response.

done – called after all requests have completed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Load TestingHTTPwrk
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.