Skip to content

Commit 07fb426

Browse files
committed
improve script
1 parent d9e85d1 commit 07fb426

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

load-test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM loadimpact/k6
2-
ENV SCRIPT hello-world-load-test.js
2+
ENV SCRIPT loadTest.js
33
COPY ./scripts /scripts
44
WORKDIR /scripts
55
# Override the entry point of the base k6 image

load-test/scripts/configuration.js

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
export const BASIC_TEST_OPTIONS = {
2-
scenarios: {
3-
// ramp up to 5 VUs over 30 seconds
4-
rampUp: {
5-
executor: "ramping-vus",
6-
startVUs: 0,
7-
stages: [
8-
{duration: '30s', target: 5}
9-
]
10-
},
11-
// have 5 VUs do 3 iterations each, up to a max of 2 minutes. Start this after
12-
// the ramp up time.
13-
highLoad: {
14-
executor: "per-vu-iterations",
15-
vus: 5,
16-
iterations: 3,
17-
maxDuration: "2m",
18-
startTime: '30s',
19-
}
20-
},
21-
thresholds: {
22-
exceptions: ["count == 0"],
23-
errors: ["count == 0"],
24-
websocket_session_duration_without_sleep: ["p(95) < 5000"],
25-
long_websocket_sessions: ["count <= 1"],
26-
extra_long_websocket_sessions: ["count == 0"]
27-
},
28-
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(98)", "p(99)"],
29-
};
30-
311
// TODO: Update to a load testing instance of Javabuilder
322
export const UPLOAD_URL = `https://javabuilder-molly-http.dev-code.org/seedsources/sources.json?Authorization=`;
333
export const WEBSOCKET_URL = `wss://javabuilder-molly.dev-code.org?Authorization=`;
@@ -50,12 +20,48 @@ export const UPLOAD_PARAMS = {
5020
export const PRIVATE_KEY = null;
5121

5222
// Thresholds for metrics
23+
// Long requests time: we don't want requests to go over this time in the p(95) case
5324
export const LONG_REQUEST_MS = 5000;
54-
export const EXTRA_LONG_REQUEST_MS = 10000;
25+
// Extra long request time: we never want requests to go over this time.
26+
export const EXTRA_LONG_REQUEST_MS = 14000;
5527

5628
// Mini-app types
5729
export const MiniAppType = {
5830
CONSOLE: 'console',
5931
NEIGHBORHOOD: 'neighborhood',
6032
THEATER: 'theater'
6133
};
34+
35+
export function getTestOptions(maxUserGoal, rampUpTimeMinutes, highLoadTimeMinutes) {
36+
const maxConcurrentUsers = Math.floor(maxUserGoal / 30);
37+
return {
38+
scenarios: {
39+
// ramp up to maxConcurrentUsers VUs over rampUpTimeMinutes
40+
rampUp: {
41+
executor: "ramping-vus",
42+
startVUs: 0,
43+
stages: [
44+
{duration: `${rampUpTimeMinutes}m`, target: maxConcurrentUsers}
45+
]
46+
},
47+
// have maxConcurrentUsers VUs do 3 iterations each minute, for a total of highLoadTimeMinutes * 3
48+
// iterations per virutal user.
49+
// Start this after the ramp up time and allow for 1 extra minute in the max duration in case of issues.
50+
highLoad: {
51+
executor: "per-vu-iterations",
52+
vus: maxConcurrentUsers,
53+
iterations: 3 * highLoadTimeMinutes, // this is iterations per virtual user
54+
maxDuration: `${highLoadTimeMinutes + 1}m`,
55+
startTime: `${rampUpTimeMinutes}m`,
56+
}
57+
},
58+
thresholds: {
59+
exceptions: ["count == 0"],
60+
errors: ["count == 0"],
61+
websocket_session_duration_without_sleep: ["p(95) < 5000"],
62+
long_websocket_sessions: [`count <= ${maxConcurrentUsers}`],
63+
extra_long_websocket_sessions: ["count == 0"]
64+
},
65+
summaryTrendStats: ["avg", "min", "med", "max", "p(90)", "p(95)", "p(98)", "p(99)"],
66+
};
67+
}

load-test/scripts/hello-world-load-test.js renamed to load-test/scripts/loadTest.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,41 @@ import { helloWorld } from "./sources.js";
66
import {
77
LONG_REQUEST_MS,
88
EXTRA_LONG_REQUEST_MS,
9-
BASIC_TEST_OPTIONS,
109
MiniAppType,
1110
UPLOAD_URL,
1211
UPLOAD_PARAMS,
1312
WEBSOCKET_URL,
14-
WEBSOCKET_PARAMS
13+
WEBSOCKET_PARAMS,
14+
getTestOptions
1515
} from "./configuration.js";
1616
import generateToken from "./generateToken.js";
1717

18-
export const options = BASIC_TEST_OPTIONS;
18+
// Change these options to increase the user goal or time to run the test.
19+
export const options = getTestOptions(
20+
/* User goal */ 150,
21+
/* Ramp up time minutes */ 1,
22+
/* High load time minutes */ 5
23+
);
24+
25+
// Change this to test different code
26+
const sourceToTest = helloWorld;
1927

2028
const exceptionCounter = new Counter("exceptions");
2129
const errorCounter = new Counter("errors");
2230
const connectToCloseTime = new Trend(
2331
"websocket_session_duration_without_sleep",
2432
true
2533
);
26-
// websocket sessions > 5 seconds
34+
// websocket sessions > LONG_REQUEST_MS
2735
const longWebsocketSessions = new Counter("long_websocket_sessions");
28-
// websocket sessions > 10 seconds
36+
// websocket sessions > EXTRA_LONG_REQUEST_MS
2937
const extraLongWebsocketSessions = new Counter("extra_long_websocket_sessions");
3038

3139
export default function () {
3240
const authToken = generateToken(MiniAppType.CONSOLE);
3341
const uploadResult = http.put(
3442
UPLOAD_URL + authToken,
35-
helloWorld,
43+
sourceToTest,
3644
UPLOAD_PARAMS
3745
);
3846
const res = ws.connect(WEBSOCKET_URL + authToken, WEBSOCKET_PARAMS, (socket) =>
@@ -50,7 +58,6 @@ function onSocketConnect(socket, startTime) {
5058
socket.on("message", function (data) {
5159
const parsedData = JSON.parse(data);
5260
if (parsedData.type === "EXCEPTION") {
53-
console.log("hit an exception " + parsedData.value);
5461
exceptionCounter.add(1);
5562
}
5663
});
@@ -68,7 +75,6 @@ function onSocketConnect(socket, startTime) {
6875
});
6976

7077
socket.on("error", function (e) {
71-
console.log("error occurred: " + e.error());
7278
errorCounter.add(1);
7379
});
7480
}

0 commit comments

Comments
 (0)