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.
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.comwrk 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
