Skip to content
Snippets Groups Projects
Commit 8c71e5ee authored by ms.evilhat's avatar ms.evilhat
Browse files

feat: add lua script to compare two k6-summary files

parent 0307ae34
No related branches found
No related tags found
1 merge request!1414sbroad import
# Load testing
## Using docker-compose
Run from sbroad directory
```
make stress test=projection
```
Parameter `test` is type of stress test (corresponding to the name of folder). As result you will see file `k6_summary.lua` with summarized metrics inside chosen stress test folder.
## Using k6 and tarantool
1. Run [test application](../test_app)
```bash
cd ../test_app && cartridge start
......@@ -20,9 +26,28 @@
1. Run the [k6](https://k6.io/docs/getting-started/running-k6/) script
```bash
./k6 run -u 10 -d 1m k6.js
./k6 run -u 10 -d 1m k6.js --summary-export k6_summary.json
```
**Note:**
**Note:**
If you run stress tests sequentially, you may need to do `cartridge clean` before next test run because tests might have
conflicting schemas.
## Compare results
If you need to compare results serveral test, you may run
```
lua compare.lua path_to_k6_summary_1.json path_to_k6_summary_2.json
```
It considered that first result must have lower rps to get 0 exit code. Example of output:
```
$ lua compare.lua path_to_k6_summary_2.json path_to_k6_summary_1.json
+----------------+-----------------+------------------+
| metrics | left result | right result |
+----------------+-----------------+------------------+
| Success value | 0.3333689238811 | 0.33428112947271 |
| Passes | 71812 | 71244 |
| Fails | 143601 | 141882 |
| VUs | 10 | 10 |
| Iterations rps | 3539.5409122402 | 3503.5619844057 |
+----------------+-----------------+------------------+
Left (first) result must have lower or equal rps
```
local json = require("json")
local function print_comparison(file1, file2)
-- Get the column headers
local headers = {"metrics", "left result", "right result" }
-- Get the row data
local rows = {
{"Success value", file1.metrics.success.value, file2.metrics.success.value},
{"Passes", file1.metrics.success.passes, file2.metrics.success.passes},
{"Fails", file1.metrics.success.fails, file2.metrics.success.fails},
{"VUs", file1.metrics.vus.value, file2.metrics.vus.value},
{"Iterations rps", file1.metrics.iterations.rate, file2.metrics.iterations.rate}
}
-- Calculate the maximum length of each column
local max_lengths = {0, 0, 0}
for i, header in ipairs(headers) do
max_lengths[i] = #header
end
for _, row in ipairs(rows) do
for i, value in ipairs(row) do
max_lengths[i] = math.max(max_lengths[i], #tostring(value))
end
end
-- Print the table
local separator = "+" .. string.rep("-", max_lengths[1] + 2)
.. "+" .. string.rep("-", max_lengths[2] + 2)
.. "+" .. string.rep("-", max_lengths[3] + 2) .. "+"
print(separator)
for i, header in ipairs(headers) do
io.write("| " .. string.format("%-" .. max_lengths[i] .. "s", header) .. " ")
end
io.write("|\n")
print(separator)
for _, row in ipairs(rows) do
for i, value in ipairs(row) do
io.write("| " .. string.format("%-" .. max_lengths[i] .. "s", tostring(value)) .. " ")
end
io.write("|\n")
end
print(separator)
end
local function load_file(file_path)
local f = assert(io.open(file_path, "r"))
local content = f:read("*all")
f:close()
return content
end
local function compare_iterations_rate(file_path1, file_path2)
local content1 = load_file(file_path1)
local content2 = load_file(file_path2)
local data1 = json.decode(content1)
local data2 = json.decode(content2)
local rate1 = data1.metrics.iterations.rate
local rate2 = data2.metrics.iterations.rate
print_comparison(data1, data2, file_path1, file_path2)
if rate1 >= rate2 then
print("Left (first) result must have lower or equal rps")
os.exit(1)
end
os.exit(0)
end
compare_iterations_rate(arg[1], arg[2])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment