Skip to content

Commit 7212836

Browse files
committed
refactor(benchmark): split k6 metrics into throughput and latency outputs
Separate benchmark-action tracking for proper regression detection: - Throughput (customBiggerIsBetter): rate in iter/s - Latency (customSmallerIsBetter): p95 and p99 in ms Adds p99 metric and configures summaryTrendStats for k6.
1 parent d66f632 commit 7212836

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

.github/workflows/benchmark.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,33 @@ jobs:
5858
RUST_BACKTRACE: "1"
5959
run: mise run k6:benchmark:continuous
6060

61-
# Store k6 benchmark result
62-
- name: Store k6 benchmark result
61+
# Store k6 throughput benchmark (higher is better)
62+
- name: Store k6 throughput benchmark
6363
uses: benchmark-action/github-action-benchmark@v1
6464
with:
65+
name: 'k6 Throughput'
6566
tool: 'customBiggerIsBetter'
66-
output-file-path: tests/benchmark/results/k6-output.json
67+
output-file-path: tests/benchmark/results/k6-throughput.json
6768
github-token: ${{ secrets.GITHUB_TOKEN }}
6869
fail-on-alert: true
6970
comment-on-alert: true
7071
summary-always: true
7172
auto-push: true
72-
benchmark-data-dir-path: docs/k6
73+
benchmark-data-dir-path: docs/k6/throughput
74+
75+
# Store k6 latency benchmark (lower is better)
76+
- name: Store k6 latency benchmark
77+
uses: benchmark-action/github-action-benchmark@v1
78+
with:
79+
name: 'k6 Latency'
80+
tool: 'customSmallerIsBetter'
81+
output-file-path: tests/benchmark/results/k6-latency.json
82+
github-token: ${{ secrets.GITHUB_TOKEN }}
83+
fail-on-alert: true
84+
comment-on-alert: true
85+
summary-always: true
86+
auto-push: true
87+
benchmark-data-dir-path: docs/k6/latency
7388

7489
# Download previous benchmark result from cache (if exists)
7590
- name: Download previous benchmark data

tests/benchmark/k6/scripts/lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function getDefaultOptions(thresholds = {}) {
3535
duration: __ENV.K6_DURATION || '30s',
3636
},
3737
},
38+
summaryTrendStats: ['min', 'avg', 'med', 'p(90)', 'p(95)', 'p(99)', 'max'],
3839
thresholds: {
3940
'iteration_duration': ['p(95)<500'],
4041
...thresholds,

tests/benchmark/k6/scripts/lib/summary.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// benchmark-action compatible output formatter
2-
// Outputs JSON array for github-action-benchmark
2+
// Outputs separate JSON files for throughput (bigger is better) and latency (smaller is better)
33
//
44
// Usage in scripts:
55
// import { createSummaryHandler } from './lib/summary.js';
@@ -15,22 +15,37 @@ export function createSummaryHandler(scriptName) {
1515
? data.metrics.iteration_duration.values['p(95)']
1616
: 0;
1717

18-
const output = [
18+
const p99Duration = data.metrics.iteration_duration
19+
? data.metrics.iteration_duration.values['p(99)']
20+
: 0;
21+
22+
// Throughput metrics (customBiggerIsBetter)
23+
const throughputOutput = [
1924
{
20-
name: `${scriptName}_iterations_per_second`,
21-
unit: 'Number',
25+
name: `${scriptName}_rate`,
26+
unit: 'iter/s',
2227
value: Math.round(iterationsPerSecond * 100) / 100,
2328
},
29+
];
30+
31+
// Latency metrics (customSmallerIsBetter)
32+
const latencyOutput = [
2433
{
25-
name: `${scriptName}_p95_ms`,
34+
name: `${scriptName}_p95`,
2635
unit: 'ms',
2736
value: Math.round(p95Duration * 100) / 100,
2837
},
38+
{
39+
name: `${scriptName}_p99`,
40+
unit: 'ms',
41+
value: Math.round(p99Duration * 100) / 100,
42+
},
2943
];
3044

3145
return {
3246
'stdout': textSummary(data),
33-
[`results/k6/${scriptName}-output.json`]: JSON.stringify(output, null, 2),
47+
[`results/k6/${scriptName}-throughput.json`]: JSON.stringify(throughputOutput, null, 2),
48+
[`results/k6/${scriptName}-latency.json`]: JSON.stringify(latencyOutput, null, 2),
3449
};
3550
};
3651
}
@@ -48,8 +63,11 @@ function textSummary(data) {
4863

4964
if (data.metrics.iteration_duration) {
5065
const dur = data.metrics.iteration_duration.values;
51-
lines.push(`duration p95: ${dur['p(95)'].toFixed(2)}ms`);
66+
lines.push(`duration min: ${dur.min.toFixed(2)}ms`);
5267
lines.push(`duration avg: ${dur.avg.toFixed(2)}ms`);
68+
lines.push(`duration p95: ${dur['p(95)'].toFixed(2)}ms`);
69+
lines.push(`duration p99: ${dur['p(99)'].toFixed(2)}ms`);
70+
lines.push(`duration max: ${dur.max.toFixed(2)}ms`);
5371
}
5472

5573
lines.push('');

tests/benchmark/mise.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,17 @@ echo '# k6 CI Benchmark: jsonb-ste-vec-insert via proxy'
230230
echo '###############################################'
231231
echo
232232
233-
mise run k6_run --script=jsonb-ste-vec-insert --target=proxy --vus=10 --duration=30s
233+
mise run k6_run --script=jsonb-ste-vec-insert --target=proxy --vus=10 --duration=60s
234234
235235
echo
236236
echo '###############################################'
237237
echo '# k6 CI Benchmark: jsonb-large-payload via proxy'
238238
echo '###############################################'
239239
echo
240240
241-
mise run k6_run --script=jsonb-large-payload --target=proxy --vus=10 --duration=30s
241+
mise run k6_run --script=jsonb-large-payload --target=proxy --vus=10 --duration=60s
242242
243-
# Merge outputs for benchmark-action
244-
jq -s 'add' results/k6/jsonb-ste-vec-insert-output.json results/k6/jsonb-large-payload-output.json > results/k6-output.json
243+
# Merge outputs for benchmark-action (separate files for throughput vs latency)
244+
jq -s 'add' results/k6/*-throughput.json > results/k6-throughput.json
245+
jq -s 'add' results/k6/*-latency.json > results/k6-latency.json
245246
"""

0 commit comments

Comments
 (0)