This explores the idea of using tests based on JUnit for load testing.
- JUnit tests run from the IDE so you can develop their functional completeness
- They offer us to include all Java libraries that we need
- With JDK 21, we have virtual threads and can run them in a non-blocking way
- Vegata shows what an output format can look like, and also provides statistics
TestLogin.java
: A unit test (which for now only calls a URL)
BaseClass.java
: Provides means to instrument the HTTP client to write a JSON file in the Vegata format
Main.java
: Run test in a JUnit
plotJava.html
: Example chart with durations
Output of cat out.json | vegeta report
:
Requests [total, rate, throughput] 1920, 305.44, 305.34
Duration [total, attack, wait] 6.288s, 6.286s, 2.043ms
Latencies [min, mean, 50, 90, 95, 99, max] 368.245µs, 18.431ms, 4.705ms, 49.09ms, 85.98ms, 200.807ms, 246.887ms
Bytes In [total, mean] 0, 0.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:640 302:1280
Error Set:
Output of cat out.json | vegeta report --type=json | jq
:
{
"latencies": {
"total": 35388185871,
"mean": 18431346,
"50th": 4704775,
"90th": 49089834,
"95th": 85980422,
"99th": 200807282,
"max": 246887483,
"min": 368245
},
"bytes_in": {
"total": 0,
"mean": 0
},
"bytes_out": {
"total": 0,
"mean": 0
},
"earliest": "2025-04-10T13:25:59.823879076Z",
"latest": "2025-04-10T13:26:06.109878634Z",
"end": "2025-04-10T13:26:06.111921615Z",
"duration": 6285999558,
"wait": 2042981,
"requests": 1920,
"rate": 305.4406832651578,
"throughput": 305.34144578248055,
"success": 1,
"status_codes": {
"200": 640,
"302": 1280
},
"errors": []
}
Vegeta: https://github.com/tsenart/vegeta
echo "GET http://localhost:8080" | vegeta attack -name=50qps -rate=50 -duration=5s > results.50qps.bin
cat results.50qps.bin | vegeta plot > plot.50qps.html
echo "GET http://localhost:8080" | vegeta attack -name=100qps -rate=100 -duration=5s > results.100qps.bin
vegeta plot results.50qps.bin results.100qps.bin > plot.html
cat results.50qps.bin results.100qps.bin | vegeta report
vegeta encode results.50qps.bin | vegeta plot > plotJson.html
cat out.json | vegeta plot > plotJava.html