Home > Net >  Socket.io: Load testing by Manual multiple client connections creation - Not working
Socket.io: Load testing by Manual multiple client connections creation - Not working

Time:03-14

I am trying to do load testing of my side which using socket.io. I would like to know how my application performing with more socket.io client connections. So, I have tired to inject multiple client connections programmatically as mentioned in Socket.io documentation https://socket.io/docs/v4/load-testing/#manual-client-creation as below.

const { io } = require("socket.io-client");

const URL = process.env.URL || "https://MYSITEURL.com";
const MAX_CLIENTS = 2;
const POLLING_PERCENTAGE = 0.05;
const CLIENT_CREATION_INTERVAL_IN_MS = 1000;
const EMIT_INTERVAL_IN_MS = 1000;

let clientCount = 0;
let lastReport = new Date().getTime();
let packetsSinceLastReport = 0;



const createClient = () => {
  // for demonstration purposes, some clients stay stuck in HTTP long-polling
  const transports =
    Math.random() < POLLING_PERCENTAGE ? ["websocket"] : ["polling", "websocket"];

    
  const socket = io(URL, {
    transports,
  });

  setInterval(() => {
    socket.emit("client to server event");
  }, EMIT_INTERVAL_IN_MS);

  socket.on("server to client event", () => {
    packetsSinceLastReport  ;
  });

  socket.on("disconnect", (reason) => {
    console.log(`disconnect due to ${reason}`);
  });

  if (  clientCount < MAX_CLIENTS) {
    setTimeout(createClient, CLIENT_CREATION_INTERVAL_IN_MS);
  }
};

createClient();

const printReport = () => {
  const now = new Date().getTime();
  const durationSinceLastReport = (now - lastReport) / 1000;
  const packetsPerSeconds = (
    packetsSinceLastReport / durationSinceLastReport
  ).toFixed(2);

  console.log(
    `client count: ${clientCount} ; average packets received per second: ${packetsPerSeconds}`
  );

  packetsSinceLastReport = 0;
  lastReport = now;
};

setInterval(printReport, 5000);
 

But on viewing the IIS requests of my site, seems only one connection is created all other connections are failing with 404 errors. Below I pasted list of logs.

My questions why for some connection my client is connection not for others. Also, in successful connection I found like one GET and POST calls are parsing but for unsuccessful connection only GET call get passed with same code, I don't know how? It would be helpful I I get any help. Thanks in advance.

Successful connection IIS log

2022-03-09 05:21:57 127.0.0.1 GET /vnext/socket.io/ EIO=4&transport=polling&t=Nzj84Vv&X-ARR-CACHE-HIT=0&X-ARR-LOG-ID=6fcf93eb-6e4f-4ab1-bc05-ace14e8218a0&SERVER-STATUS=200 443 - XXX.X.X.X Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0 - 200 0 0 572
2022-03-09 05:21:57 XXX.X.X.X POST /vnext/socket.io/ EIO=4&transport=polling&t=Nzj874I&sid=lICvErLJGwMgaV2ZAADP&X-ARR-CACHE-HIT=0&X-ARR-LOG-ID=82cbb426-5a80-4553-8155-dedf522fe489&SERVER-STATUS=200 443 - 127.0.0.1 Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0 - 200 0 0 6

For Unsuccessful call IIS logs*

2022-03-09 05:23:16 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8P-K&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 939
2022-03-09 05:23:16 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8Ppj&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 1068
2022-03-09 05:23:16 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8PvO&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 944
2022-03-09 05:23:18 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8Qnt&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 2
2022-03-09 05:23:18 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8Qno&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 3
2022-03-09 05:23:18 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8QpT&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 6
2022-03-09 05:23:18 XXX.X.X.X GET /socket.io/ EIO=4&transport=polling&t=Nzj8Qyg&b64=1 443 - XXX.X.X.X node-XMLHttpRequest - 404 0 2 3

CodePudding user response:

The issue is I have missed to add custom path in socket.io client connection. Changing the below code

const socket = io(URL, { transports, });

to

const socket = io(URL, { transports, path : {my_custom_path} });

solves this issue. Hope this helps others.

  • Related