wrk – HTTP benchmarking tool

Warning : WRK is great but written in C and not updated and maintained any longer for several years

How to install

Download a tagged version or clone the repository of the application and run the make command to build it.
Website: https://github.com/wg/wrk

Command Line Options

-c, --connections: total number of HTTP connections to keep open with
                   each thread handling N = connections/threads
 
-d, --duration:    duration of the test, e.g. 2s, 2m, 2h
 
-t, --threads:     total number of threads to use
 
-s, --script:      LuaJIT script, see SCRIPTING
 
-H, --header:      HTTP header to add to request, e.g. "User-Agent: wrk"
 
    --latency:     print detailed latency statistics
 
    --timeout:     record a timeout if a response is not received within
                   this amount of time.

Usages

Basic Usage

wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open.
Output:

Running 30s test @ http://127.0.0.1:8080/index.html
  12 threads and 400 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 30.00s, 17.76GB read
Requests/sec: 748868.53
Transfer/sec:    606.33MB

Complex usage

The idea is to write a Lua script to customize the part we need, such as adding delay between requests, adding headers or parameters in the request, or generating a report.
Example with a JSON request post:
post_person.lua :

wrk.method = "POST"
wrk.body = '{"lastname":"David", "firstname":"Doe"}'
wrk.headers["Content-Type"] = "application/json"

Here the command we pass to execute it:
wrk -t12 -c100 -d10s -s post_person.lua http://localhost:8090/person
Output of wrk:

Running 10s test @ http://localhost:8090/person
  12 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    66.96ms   36.04ms 347.53ms   86.38%
    Req/Sec   126.98     43.76   303.00     71.21%
  14916 requests in 10.05s, 2.16MB read
Requests/sec:   1483.76
Transfer/sec:    219.53KB

Output sample of the backend server:

...........
spring-boot-app_1  | 2023-05-03 08:46:23.121  INFO 1 --- [.0-8090-exec-29] davidxxx.PersonController                : Person saved=Person{id=-7750888326767463399, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.122  INFO 1 --- [.0-8090-exec-27] davidxxx.PersonController                : Person saved=Person{id=-8398726709652254714, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.125  INFO 1 --- [.0-8090-exec-84] davidxxx.PersonController                : Person saved=Person{id=5091417777412653865, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.129  INFO 1 --- [0.0-8090-exec-6] davidxxx.PersonController                : Person saved=Person{id=5271453044660262593, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.122  INFO 1 --- [.0-8090-exec-45] davidxxx.PersonController                : Person saved=Person{id=-8333314451463513325, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.130  INFO 1 --- [.0-8090-exec-74] davidxxx.PersonController                : Person saved=Person{id=-6964980761094751469, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.132  INFO 1 --- [.0-8090-exec-94] davidxxx.PersonController                : Person saved=Person{id=7442289142406121039, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.135  INFO 1 --- [.0-8090-exec-32] davidxxx.PersonController                : Person saved=Person{id=-4480504607655627430, firstname='Doe', lastname='David'}
spring-boot-app_1  | 2023-05-03 08:46:23.141  INFO 1 --- [.0-8090-exec-28] davidxxx.PersonController                : Person saved=Person{id=-7037435173743924728, firstname='Doe', lastname='David'}
...........

Example with a JSON request post and a random delay (between 500 and 800ms) between the request :
post_person.lua :

wrk.method = "POST"
wrk.body = '{"lastname":"David", "firstname":"Doe"}'
wrk.headers["Content-Type"] = "application/json"
 
function delay()
    return math.random(500, 800)
end

Output of wrk:

Running 10s test @ http://localhost:8090/person
  12 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.76ms    3.36ms  28.09ms   87.29%
    Req/Sec    14.34      9.13    50.00     74.94%
  1416 requests in 10.02s, 209.34KB read
Requests/sec:    141.33
Transfer/sec:     20.89KB
Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *