less than 20vu, the number of received messages is greater than that of sent messages. 1000vu, the received message is less than the sent message.What’s the reason?
import ws from 'k6/ws';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '20m', target: 1000 },
// { duration: '10m', target: 1000 },
],
};
export default function (tuid,suid,classRoomName) {
console.log(`VU ${__VU} `);
var classPeople = 5;//Set class capacity 1V4
var isTeacher = true;
if (`${__VU}`% classPeople == 1) {
isTeacher=true;
tuid=`10032${__VU}`;
console.log('teacheruid'+tuid);
}else{
isTeacher=false;
suid=`20022${__VU}`;
console.log('studentuid'+suid);
}
var roomId= Math.floor((__VU-1)/classPeople+1);
classRoomName='test'+roomId;
var url;
if (isTeacher) {//teacher
url= `wss://msghub.sim.kk.com/connect/token/${classRoomName}/?uid=`+tuid+``;
}else{// student
url= `wss://msghub.sim.kk.com/connect/token/${classRoomName}/?uid=`+suid+``;
}
console.log(`VU ${__VU}:`+ url);
const params = {
// tags: { my_tag: 'my ws session' }
};
var version ;
var stu_version;
const res = ws.connect(url, params, function (socket) {
socket.on('open', function open() {
console.log(`VU ${__VU}: connected`);
if (isTeacher) {
console.log('tea:'+tuid);
for (var i = 1; i <= classPeople-1; i++) {
socket.send(JSON.stringify(message));//
}
socket.send(JSON.stringify(message));
socket.setInterval(function timeout() {
socket.send(JSON.stringify(message}));
version++;
socket.send(JSON.stringify(message));
version++;
}, 3000);
} else {
socket.send(JSON.stringify(mesage));
socket.send(JSON.stringify(messge));
socket.setInterval(function timeout() {
socket.send(JSON.stringify(message}));
stu_version++;
socket.send(JSON.stringify(message));
stu_version++;
}, 3000);
}
});
socket.on('close', function () {
console.log(`VU ${__VU}: disconnected`);
});
socket.on('message', function (message) {
console.log(`VU ${__VU} received :` , message);
const msg = JSON.parse(message);
// {"result":null,"id":1}
if (msg.id == 1) {
if (msg.result == null) {
// console.log('message_id_1');
version=1;
} else {
version = msg.result.version;
version++;
}
}
if (msg.id == 4) {
if (msg.result == null) {
stu_version=1;
}else{
stu_version=msg.result.version;
stu_version++;
}
}
});
socket.setTimeout(function () {
socket.close();
}, 30000);
});
check(res, { 'Connected successfully': (r) => r && r.status === 101 });
}
Why, some VUs did not start, or some vUs started but did not execute its own default function
It seems some connections are timed out, you should set a lower timeout value and log for getting feedback, it could be useful also to set an error handler as explained in this documentation’s example.
Is the value of iteration_duration expected for you?
Hi @bingbing,
is the server or client responsible for closing the WebSocket connection in your application? What is the p(95) value for iteration duration in the 20VUs case? Is it mostly the same?
Have you checked that your server is handling the connections properly and it’s not experiencing any trouble at scale?
You could check logs and see if any error is generated from your application
The CPU is not the unique value to check: if the application depends on other services/components then the high latency could be generated on that side. You should check the tracing of your system.