Socket.io:通过手动创建多个客户端连接进行负载测试 - 不工作
Socket.io: Load testing by Manual multiple client connections creation - Not working
我正在尝试使用 socket.io 对我这边进行负载测试。我想知道我的应用程序如何在更多 socket.io 客户端连接下执行。因此,我厌倦了以编程方式注入多个客户端连接,如下面 Socket.io 文档 https://socket.io/docs/v4/load-testing/#manual-client-creation 中所述。
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);
但是在查看我网站的 IIS 请求时,似乎只创建了一个连接,所有其他连接都失败并出现 404 错误。下面我粘贴了日志列表。
我的问题是为什么对于某些连接我的客户端是连接而不是其他连接。另外,在成功的连接中,我发现像一个 GET 和 POST 调用正在解析,但对于不成功的连接,只有 GET 调用通过相同的代码传递,我不知道如何?我得到任何帮助会很有帮助。提前致谢。
成功连接IIS日志
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
调用IIS失败日志*
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
问题是我错过了在 socket.io 客户端连接中添加自定义路径。更改以下代码
const socket = io(URL, {
运输,
});
至
const socket = io(URL, {
运输,
路径:{my_custom_path}
});
解决了这个问题。希望这对其他人有帮助。
我正在尝试使用 socket.io 对我这边进行负载测试。我想知道我的应用程序如何在更多 socket.io 客户端连接下执行。因此,我厌倦了以编程方式注入多个客户端连接,如下面 Socket.io 文档 https://socket.io/docs/v4/load-testing/#manual-client-creation 中所述。
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);
但是在查看我网站的 IIS 请求时,似乎只创建了一个连接,所有其他连接都失败并出现 404 错误。下面我粘贴了日志列表。
我的问题是为什么对于某些连接我的客户端是连接而不是其他连接。另外,在成功的连接中,我发现像一个 GET 和 POST 调用正在解析,但对于不成功的连接,只有 GET 调用通过相同的代码传递,我不知道如何?我得到任何帮助会很有帮助。提前致谢。
成功连接IIS日志
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
调用IIS失败日志*
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
问题是我错过了在 socket.io 客户端连接中添加自定义路径。更改以下代码
const socket = io(URL, { 运输, });
至
const socket = io(URL, { 运输, 路径:{my_custom_path} });
解决了这个问题。希望这对其他人有帮助。