123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import { io } from "socket.io-client";
- import customParser from "socket.io-msgpack-parser";
- const URL = process.env.URL || "wss://test-socket.4dkankan.com";
- // http://zhang9394@zhangyupeng:face3d.4dage.com:7005/zhangyupeng/chatIM.git
- const MAX_CLIENTS = 500;
- const POLLING_PERCENTAGE = 0.05;
- const CLIENT_CREATION_INTERVAL_IN_MS = 10;
- const EMIT_INTERVAL_IN_MS = 1000;
- // wws://test-socket.4dkankan.com/watch
- let clientCount = 0;
- let lastReport = new Date().getTime();
- let packetsSinceLastReport = 0;
- let testSceneNum = "t-test";
- let roomId = "00001";
- let userLimitNum = 2000;
- let agentId = 0;
- const createAgent = () => {
- agentId += 1;
- const nickName = `test_name_${agentId}`;
- const userId = `6666666${agentId}`;
- const role = agentId === 1 ? "leader" : "customer";
- createClient({ userId, nickName, from: "0", role: role });
- createClient({ userId, nickName, from: "1", role: role });
- createClient({ userId, nickName, from: "2", role: role });
- };
- const createClient = ({ userId, nickName, from, role }) => {
- // for demonstration purposes, some clients stay stuck in HTTP long-polling
- const socket = io(URL, {
- path: "/fsl-node",
- transport: ["websocket"],
- parser: customParser,
- query: {
- userId: userId,
- from: from || 2,
- sceneNum: testSceneNum,
- role: role,
- nickName: nickName,
- roomId: roomId,
- voiceStatus: 0,
- enableTalk: true,
- isAuthMic: 0,
- isAllowMic: 0,
- userLimitNum,
- myHeadUrl: "http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg",
- },
- });
- 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(createAgent, CLIENT_CREATION_INTERVAL_IN_MS);
- }
- };
- createAgent();
- 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);
|