After struggling against k6, with the help of the answers to my other question, i was able (i think) to test subscriptions with websocket.
Now i'm trying to desing a good test. Our app is a Single Page App that mainly uses websocket subscriptions instead of queries. The problem is that i'm a bit lost on how to define how many subscriptiosn i should test in order to detect if my app will be able to support around 800 users working simultaneously in real time. (I started testing it first with a top of 150 VUs).
For now, i'm running the test with 3 commonly used subscriptions in our user path, but:
Should I try more subscriptions, trying to cover the most used ones in our user path, or should I keep it simple and pick the 3 most used ones and add a timeout between them?
Is this a correct approach for load/stress testing with GRAPHQL subscriptions/websocket? I'm not sure if i'm being too cautious about this, but i'm afraid of giving a false status about our situation.
I am a bit confused on how to interpret the results screen, especially on how I can infer if we will be able to give a good experience to our users. Should I take the avg and p(95) of ws_ping as a reference for this?
As a reference, here is part of the code i'm using to perform the test
Thanks in advance!
main.js
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.5/index.js';
const session = new Httpx({
baseURL: `https://${enviorment}`
});
const wsUri = `wss://${enviorment}/v1/graphql`;
const pauseMin = 2;
const pauseMax = 6;
export const options = {
stages: [
{ duration: '30s', target: 50 },
{ duration: '30s', target: 100 },
{ duration: '30s', target: 150 },
{ duration: '120s', target: 150 },
{ duration: '60s', target: 50 },
{ duration: '30s', target: 0 },
]
};
export default function () {
session.addHeader('Content-Type', 'application/json');
todas(keys.profesorFirebaseKey, keys.desafioCursoKey, keys.nivelCurso, keys.profesorKey)
}
todas.js:
import ws from 'k6/ws';
import {fail,check} from 'k6'
import exec from 'k6/execution';
export function todas(id, desafioCursoKey, nivel, profesorKey) {
const queryList = [`];
let ArraySubscribePayload = []
for (let i = 0; i < 3; i++) {
let subscribePayload = {
id: String(1 + 3 * i),
payload: {
extensions: {},
query: queryList[i],
variables: {},
},
type: "start",
}
ArraySubscribePayload.push(subscribePayload)
}
const initPayload = {
payload: {
headers: {
xxxxxxxxxxxxx
},
lazy: true,
},
type: "connection_init",
};
const res = ws.connect(wsUri, initPayload, function (socket) {
socket.on('open', function () {
socket.setInterval(function timeout() {
socket.send(JSON.stringify(initPayload));
socket.send(JSON.stringify(ArraySubscribePayload[0]));
socket.setTimeout(function timeout() {
socket.send(JSON.stringify(ArraySubscribePayload[1]));
socket.send(JSON.stringify(ArraySubscribePayload[2]));
ArraySubscribePayload[1].id = String(parseInt(ArraySubscribePayload[1].id) + 1)
ArraySubscribePayload[2].id = String(parseInt(ArraySubscribePayload[2].id) + 1)
}, 3000);
ArraySubscribePayload[0].id = String(parseInt(ArraySubscribePayload[0].id) + 1)
socket.ping();
}, 7000);
})
});
}