-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from zapier/add-k6-benchmark
Add a k6.io benchmark
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Benchmarking | ||
We are using [k6](https://k6.io/) for our benchmarking. To run one of the performance | ||
tests you can do: | ||
|
||
``` | ||
k6 run -e PAG_HOST=http://localhost --vus 10 --duration 30s benchmarking/labels.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import http from 'k6/http'; | ||
import { check } from 'k6'; | ||
|
||
|
||
const jobs = [ | ||
"job1", | ||
"job2", | ||
"job3", | ||
"job4", | ||
] | ||
|
||
const labels = [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
] | ||
|
||
|
||
const labelValues = [ | ||
"qux", | ||
"fred", | ||
"thud", | ||
] | ||
|
||
function getRandInteger(min, max) { | ||
return Math.floor(Math.random() * (max - min) ) + min; | ||
} | ||
|
||
function randChoice(arr) { | ||
return arr[Math.floor(Math.random() * arr.length)]; | ||
} | ||
|
||
export default function () { | ||
const randomJob = randChoice(jobs); | ||
const randomLabel = randChoice(labels); | ||
const randomValue = randChoice(labelValues); | ||
|
||
const url = `${__ENV.PAG_HOST}/metrics/job/${randomJob}/${randomLabel}/${randomValue}`; | ||
const randomMetric1 = getRandInteger(1, 50) | ||
const randomMetric2 = getRandInteger(1000, 3000) | ||
const randomMetric3 = getRandInteger(3000, 4000) | ||
|
||
const payload = ` | ||
# TYPE some_metric counter | ||
some_metric{label="val1"} ${randomMetric1} | ||
# TYPE another_metric gauge | ||
# HELP another_metric Just an example. | ||
another_metric ${randomMetric2} | ||
k6_http_requests_total{method="post",code="200"} ${randomMetric3} | ||
` | ||
|
||
const params = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const res = http.post(url, payload, params); | ||
check(res, { 'status was 200ish': (r) => r.status < 300 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import http from 'k6/http'; | ||
import { check } from 'k6'; | ||
|
||
function getRandInteger(min, max) { | ||
return Math.floor(Math.random() * (max - min) ) + min; | ||
} | ||
|
||
/* | ||
Original prom-agg-gateway doesn't support labels so this perf test | ||
is here mostly to compare against them. | ||
*/ | ||
export default function () { | ||
const url = `${__ENV.PAG_HOST}/metrics/`; | ||
|
||
const randomMetric1 = getRandInteger(1, 50) | ||
const randomMetric2 = getRandInteger(1000, 3000) | ||
const randomMetric3 = getRandInteger(3000, 4000) | ||
|
||
const payload = ` | ||
# TYPE some_metric counter | ||
some_metric{label="val1"} ${randomMetric1} | ||
# TYPE another_metric gauge | ||
# HELP another_metric Just an example. | ||
another_metric ${randomMetric2} | ||
k6_http_requests_total{method="post",code="200"} ${randomMetric3} | ||
` | ||
|
||
const params = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const res = http.post(url, payload, params); | ||
check(res, { 'status was 200ish': (r) => r.status < 300 }); | ||
} |