How to install wrk on Ubuntu
To install wrk
on Ubuntu, you need to run:
sudo apt-get update
sudo apt-get install wrk
wrk
package comes standard in the Ubuntu package list.
root@ubuntu-test-bench:~# sudo apt-get update; sudo apt-get install wrk
Hit:1 https://mirror.hetzner.com/ubuntu/packages jammy InRelease
Hit:2 https://mirror.hetzner.com/ubuntu/packages jammy-updates InRelease
Hit:3 https://mirror.hetzner.com/ubuntu/packages jammy-backports InRelease
Hit:4 https://mirror.hetzner.com/ubuntu/security jammy-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libluajit-5.1-2 libluajit-5.1-common
The following NEW packages will be installed:
libluajit-5.1-2 libluajit-5.1-common wrk
0 upgraded, 3 newly installed, 0 to remove and 69 not upgraded.
Need to get 329 kB of archives.
After this operation, 899 kB of additional disk space will be used.
Do you want to continue? [Y/n]
What is wrk?
wrk
is a popular open-source command-line tool used for benchmarking and testing the performance of web servers and web applications. It's designed to simulate a high load of HTTP requests to measure how well a web server or application can handle the load and respond to requests under various conditions.
Key features of wrk
include:
-
HTTP Benchmarking:
wrk
allows you to simulate a specified number of concurrent users (threads) making HTTP requests to a target server. It can generate a significant amount of load on the server to test its performance. -
Customizable Requests: You can customize the HTTP requests being sent by specifying headers, request methods, and request bodies. This enables you to simulate different types of requests that your application might receive.
-
Detailed Reporting:
wrk
provides detailed output about request and response times, throughput (requests per second), and latency distribution. This information helps you understand how well your server performs under different workloads. -
Lua Scripting:
wrk
supports Lua scripting, allowing you to create more complex and realistic load scenarios. You can write Lua scripts to define custom request patterns, headers, and behaviors. -
SSL/TLS Support: The tool can also benchmark HTTPS endpoints with SSL/TLS encryption.
-
Concurrency and Threads:
wrk
lets you specify the number of concurrent connections (threads) to simulate, which can help you understand how your server performs under high concurrency. -
Latency Distribution: It provides information about the distribution of latencies, giving insights into the consistency and variability of response times.
-
Warm-up Periods:
wrk
allows you to define a warm-up period before the actual benchmarking starts. This helps to reach a steady state and avoid initial spikes. -
Timeouts and Errors: You can configure timeouts and error handling behavior to see how your application handles failing requests.
Overall, wrk
is a versatile tool used by developers, performance engineers, and system administrators to assess the performance of web servers and applications, identify bottlenecks, and optimize their systems for better scalability and responsiveness.
Basic wrk
usage
wrk -t6 -c200 -d45s http://127.0.0.1:8080/index.html
This will run a benchmark for 45 seconds, using 6 threads, and keeping 200 HTTP connections open.
Output
Running 45s test @ http://127.0.0.1:8080/index.html
6 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 635.91us 0.89ms 12.92ms 93.69%
Req/Sec 56.20k 8.07k 62.00k 86.54%
22464657 requests in 45.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec: 606.33MB