Skip to content

Commit 239b348

Browse files
committed
Adjust load test script for session transfer testing
1 parent 215a5b6 commit 239b348

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

test/load/script.js

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import http from "k6/http";
22
import { check } from "k6";
33

4-
const PAYLOAD = JSON.stringify({
5-
n: "pageview",
6-
u: "http://dummy.site/some-page",
7-
d: "dummy.site",
8-
r: null,
9-
w: 1666,
10-
});
4+
function payload(pages) {
5+
return JSON.stringify({
6+
n: "pageview",
7+
u: pages[Math.floor(Math.random() * pages.length)],
8+
d: "dummy.site",
9+
r: null,
10+
w: 1666,
11+
});
12+
}
1113

1214
function newParams() {
1315
const ip =
@@ -29,24 +31,60 @@ function newParams() {
2931
};
3032
}
3133

34+
function getClient(clients) {
35+
return clients[Math.floor(Math.random() * clients.length)];
36+
}
37+
38+
function getClientSliding(clients, start, runtime, windowSize) {
39+
const now = performance.now();
40+
const seconds = Math.floor((now - start) / 1000);
41+
let lowerBound = Math.max(seconds - windowSize, 0);
42+
const upperBound = Math.min(lowerBound + 2 * windowSize, runtime);
43+
if (upperBound - lowerBound < 2 * windowSize) {
44+
lowerBound = upperBound - 2 * windowSize;
45+
}
46+
const lowerIndex = (lowerBound / runtime) * clients.length;
47+
const upperIndex = (upperBound / runtime) * clients.length;
48+
const indexWindow = upperIndex - lowerIndex;
49+
50+
return clients[lowerIndex + Math.floor(Math.random() * indexWindow)];
51+
}
52+
53+
export function setup() {
54+
const start = performance.now();
55+
56+
const clients = Array(2000)
57+
.fill(0)
58+
.map((_) => newParams());
59+
60+
const pages = Array(100)
61+
.fill(0)
62+
.map((_, i) => `http://dummy.site/some-page-${i}`);
63+
64+
return { clients: clients, pages: pages, start: start };
65+
}
66+
3267
export const options = {
3368
scenarios: {
3469
constant_rps: {
3570
executor: "constant-arrival-rate",
36-
rate: 12000,
71+
rate: 50,
3772
timeUnit: "1s",
38-
duration: "15m",
73+
duration: "10m",
3974
preAllocatedVUs: 10000,
4075
maxVUs: 30000,
4176
},
4277
},
4378
};
4479

45-
export default function () {
80+
export default function (data) {
81+
const client = getClient(data.clients);
82+
// const client = getClientSliding(data.clients, data.start, 600, 60);
83+
4684
const res = http.post(
47-
"http://localhost:8000/api/event",
48-
PAYLOAD,
49-
newParams(),
85+
"http://localhost:4000/api/event",
86+
payload(data.pages),
87+
getClient(data.clients),
5088
);
5189

5290
check(res, {

0 commit comments

Comments
 (0)