Table of Contents
“wrk” is a tool used for performance testing and load testing, specifically designed for evaluating the performance of web servers that support the HTTP and HTTPS protocols. It sends requests to a web server under a specified load and measures response times, request counts, and other performance metrics to analyze the server’s performance.
Here are some key features of wrk:
- High Performance: wrk has the capability to send a high volume of HTTP requests rapidly, making it suitable for simulating real-world usage conditions.
- Flexible Configuration: Users can customize the load test by specifying various parameters. These parameters include the number of connections, request rate, duration of the test, and the content of the requests.
- Quick and Simple Installation: wrk is an easy-to-use tool that can be quickly installed. It is typically run from the command line interface.
- Advanced Metrics: During a performance test, wrk can record various metrics and present them to the user. These metrics may include time per request, transfer rate per request, and other measurements.
wrk is known for its flexibility and extensive feature set, making it a preferred choice for developers and system administrators who want to understand and optimize the performance of web servers and applications.
wrk
, the process is typically straightforward and performed through the command line interface. Here are the steps to install wrk
on different operating systems:Linux (Ubuntu):
- Open the terminal and use the following commands to install
wrk
:sudo apt-get update sudo apt-get install wrk
macOS:
- Open the terminal and use the Homebrew package manager to install
wrk
:brew install wrk
Windows:
- To use
wrk
on Windows, you may need to first set up the Windows Subsystem for Linux (WSL) or create a Unix-based terminal environment. Follow these steps:- Install Windows Subsystem for Linux (WSL): WSL Installation Guide
- Then, install an Ubuntu or Debian-based distribution through WSL and follow the Linux installation steps mentioned above.
Verify Successful Installation:
After installation, to confirm that wrk
is installed correctly, open the terminal or command prompt and type the following command:
wrk --version
This command should display the installed version of wrk
.
By following these steps, you should successfully install wrk
and be able to use it to test the performance of web servers.
Basic wrk
Command:
wrk -t12 -c400 -d30s http://example.com
-t
: Number of threads (virtual users).-c
: Number of connections (concurrent connections).-d
: Duration of the test.
Advanced Options:
- Specify Request Method:
wrk -t12 -c400 -d30s -s script.lua http://example.com
Use a Lua script (script.lua) to define custom HTTP requests.
- HTTP Headers:
wrk -t12 -c400 -d30s --header "Authorization: Bearer token" http://example.com
Add custom HTTP headers to requests.
- Adjust Connection Timeout:
wrk -t12 -c400 -d30s --timeout 5s http://example.com
Set the maximum time to wait for a connection to be established.
- Print Detailed Latency Statistics:
wrk -t12 -c400 -d30s --latency http://example.com
Print detailed latency statistics.
- Customized Output Format:
wrk -t12 -c400 -d30s -L http://example.com
Log results in a format suitable for input to gnuplot.
Lua Script Example (script.lua):
wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.body = '{"key": "value"}'
Result Analysis:
- Requests per Second (RPS):
- Measure the number of requests processed per second.
- Latency:
- Analyze the time it takes for each request to receive a response.
- Throughput:
- Examine the data transfer rate between the client and server.
- Concurrency:
- Assess how many concurrent connections the server can handle.
Examples:
- Test with Increased Thread Count:
wrk -t24 -c800 -d30s http://example.com
Test with 24 threads and 800 connections.
- Test with Longer Duration:
wrk -t12 -c400 -d60s http://example.com
Test for 60 seconds instead of the default 30 seconds.
Remember to adjust parameters based on your specific testing requirements and the characteristics of the web application you are evaluating. For more detailed information, refer to the wrk
documentation: wrk GitHub Repository