Stress Testing Server with 100 Concurrent Connections Using K6

Hello TechSoft3D Team,

We have successfully deployed our client-server application. We have conducted load testing with 100 concurrent connections using the K6 Load Testing Tool. Below is a sample script we used for this test.

import http from ‘k6/http’;
import ws from ‘k6/ws’;

const BASE_HTTP_URL = ‘http://172.16.16.93:8082/project2/TS051’;

export const options = {
scenarios: {
ws_test: {
executor: ‘per-vu-iterations’,
vus: 100,
iterations: 1,
maxDuration: ‘1m’,
},
},
};

export default function () {
// Perform HTTP GET to retrieve spawnId
const res = http.get(BASE_HTTP_URL);

if (res.status !== 200 && res.status !== 201) {
console.error(❌ HTTP request failed with status: ${res.status});
return;
}

let spawnId;
try {
spawnId = res.json().spawnId;
} catch (e) {
console.error(❌ Failed to parse JSON response: ${e.message});
return;
}

if (!spawnId) {
console.error(‘:cross_mark: Missing spawnId in HTTP response’);
return;
}

const wsUrl = ws://172.16.16.93:8082/${spawnId};

const response = ws.connect(wsUrl, {}, (socket) => {
socket.on(‘open’, () => {
console.log(✅ VU ${__VU} connected to ${wsUrl});
});

socket.on('error', (e) => {
  console.error(`❌ VU ${__VU} WebSocket error: ${e.error()}`);
});

socket.setTimeout(() => {
  socket.close();
  console.log(`🕒 VU ${__VU} WebSocket closed after timeout`);
}, 60000); // Close connection after 60 seconds

});

if (response && response.error) {
console.error(❌ WebSocket connection error: ${response.error()});
}
}

Could you please advise on how to perform a stress test targeting 100 concurrent connections effectively? We want to understand best practices and any additional configurations needed to simulate stress conditions on the server.

Thank you for your support.

We’re glad to hear that you have successfully deployed your application.

In terms of guidance on writing appropriate stress testing on K6, we would prefer to defer this to the K6 community as they would be more qualified to assist you.