Created
October 30, 2023 16:07
-
-
Save dgzlopes/f00ee0def864f32f96698f84eaebc36a to your computer and use it in GitHub Desktop.
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
import { sleep } from "k6"; | |
import { openKv } from "k6/x/kv"; | |
export const options = { | |
scenarios: { | |
poll: { | |
exec: "poll", | |
executor: "constant-vus", | |
vus: 1, | |
duration: "20s", | |
}, | |
write: { | |
exec: "write", | |
executor: "ramping-vus", | |
stages: [ | |
{ duration: '5s', target: 5 }, | |
{ duration: '10s', target: 5 }, | |
{ duration: '5s', target: 0 }, | |
], | |
}, | |
}, | |
}; | |
const polling_kv = openKv(); | |
export async function setup() { | |
await polling_kv.clear(); | |
} | |
export async function poll() { | |
const entries = await polling_kv.list({ prefix: "request_" }); | |
for (const entry of entries) { | |
console.log(`poll request (iteration_${__ITER}): ${entry.key}`); | |
polling_kv.delete(entry.key); | |
} | |
} | |
export async function write() { | |
// If request takes more than X seconds -> Send it to the polling queue | |
await polling_kv.set(`request_${__VU}_${__ITER}`, "value"); | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment