gemercheung 3 years ago
parent
commit
c914776b96
5 changed files with 46 additions and 11 deletions
  1. 1 1
      .env.development
  2. 1 0
      src/controller/room/index.js
  3. 1 1
      src/core/logger.js
  4. 4 0
      start.sh
  5. 39 9
      test/muti-client.js

+ 1 - 1
.env.development

@@ -2,7 +2,7 @@ PORT=12001
 SOCKET_PORT=12001
 SOCKET_PORT=12001
 CONTAINER_NAME='socket-chat-IM'
 CONTAINER_NAME='socket-chat-IM'
 VOLUME_DIR=./data
 VOLUME_DIR=./data
-REDIS_HOST=192.168.10.235
+REDIS_HOST=127.0.0.1
 REDIS_PORT=6379
 REDIS_PORT=6379
 REDIS_DB=10
 REDIS_DB=10
 REDIS_PASSWORD=redis9394
 REDIS_PASSWORD=redis9394

+ 1 - 0
src/controller/room/index.js

@@ -109,6 +109,7 @@ export class RoomController extends BasicController {
               userLimitNum: this.user.userLimitNum,
               userLimitNum: this.user.userLimitNum,
               enableTalk: this.user.enableTalk === "true" ? true : false,
               enableTalk: this.user.enableTalk === "true" ? true : false,
             };
             };
+            console.log("roomConfig", roomConfig);
             // console.log("roomConfig", roomConfig);
             // console.log("roomConfig", roomConfig);
             await setRoomConfig(this.roomId, roomConfig);
             await setRoomConfig(this.roomId, roomConfig);
           }
           }

+ 1 - 1
src/core/logger.js

@@ -60,7 +60,7 @@ const logger = createLogger({
 
 
   format: format.combine(
   format: format.combine(
     format.colorize(),
     format.colorize(),
-    format.timestamp({ format: "MMM D, YYYY HH:mm:ss.SSS" }),
+    format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
     customFormat,
     customFormat,
     // Do not use splat format
     // Do not use splat format
   ),
   ),

+ 4 - 0
start.sh

@@ -5,8 +5,10 @@ cp .env.production .env
 source .env
 source .env
 
 
 echo "port: $PORT"
 echo "port: $PORT"
+echo "port1: $PORT1"
 echo "SOCKET_PORT: $SOCKET_PORT"
 echo "SOCKET_PORT: $SOCKET_PORT"
 echo "CONTAINER_NAME: $CONTAINER_NAME"
 echo "CONTAINER_NAME: $CONTAINER_NAME"
+echo "CONTAINER_NAME1: $CONTAINER_NAME1"
 echo "SOCKET_PATH: $SOCKET_PATH"
 echo "SOCKET_PATH: $SOCKET_PATH"
 
 
 
 
@@ -14,6 +16,7 @@ if [ ! "$(docker ps -q -f name=$CONTAINER_NAME))" ]; then
     if [ "$(docker ps -aq -f status=exited -f name=$CONTAINER_NAME))" ]; then
     if [ "$(docker ps -aq -f status=exited -f name=$CONTAINER_NAME))" ]; then
         # cleanup
         # cleanup
         docker rm $CONTAINER_NAME -f
         docker rm $CONTAINER_NAME -f
+        docker rm $CONTAINER_NAME1 -f
         # docker rm "$CONTAINER_NAME-redis" -f
         # docker rm "$CONTAINER_NAME-redis" -f
     fi
     fi
     # run your container
     # run your container
@@ -23,6 +26,7 @@ else
     if [ "$(docker ps -aq -f status=running -f name=$CONTAINER_NAME))" ]; then
     if [ "$(docker ps -aq -f status=running -f name=$CONTAINER_NAME))" ]; then
         # cleanup
         # cleanup
         docker rm $CONTAINER_NAME -f
         docker rm $CONTAINER_NAME -f
+        docker rm $CONTAINER_NAME1 -f
         #  docker rm "$CONTAINER_NAME-redis" -f
         #  docker rm "$CONTAINER_NAME-redis" -f
     fi
     fi
     echo "has container and docker-compose up"
     echo "has container and docker-compose up"

+ 39 - 9
test/muti-client.js

@@ -1,21 +1,51 @@
 import { io } from "socket.io-client";
 import { io } from "socket.io-client";
-const URL = process.env.URL || "http://127.0.0.1:3000";
-const MAX_CLIENTS = 10000;
+import customParser from "socket.io-msgpack-parser";
+const URL = process.env.URL || "wss://test-socket.4dkankan.com";
+
+const MAX_CLIENTS = 600;
 const POLLING_PERCENTAGE = 0.05;
 const POLLING_PERCENTAGE = 0.05;
 const CLIENT_CREATION_INTERVAL_IN_MS = 10;
 const CLIENT_CREATION_INTERVAL_IN_MS = 10;
 const EMIT_INTERVAL_IN_MS = 1000;
 const EMIT_INTERVAL_IN_MS = 1000;
-
+// wws://test-socket.4dkankan.com/watch
 let clientCount = 0;
 let clientCount = 0;
 let lastReport = new Date().getTime();
 let lastReport = new Date().getTime();
 let packetsSinceLastReport = 0;
 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" : "role";
+  createClient({ userId, nickName, from: '0', role });
+  createClient({ userId, nickName, from: '1', role });
+  createClient({ userId, nickName, from: '2', role });
+};
 
 
-const createClient = () => {
+const createClient = ({ userId, nickName, from, role }) => {
   // for demonstration purposes, some clients stay stuck in HTTP long-polling
   // for demonstration purposes, some clients stay stuck in HTTP long-polling
-  const transports = Math.random() < POLLING_PERCENTAGE ? ["websocket"] : ["websocket", "websocket"];
 
 
   const socket = io(URL, {
   const socket = io(URL, {
-    path: "/test",
-    transports,
+    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(() => {
   setInterval(() => {
@@ -31,11 +61,11 @@ const createClient = () => {
   });
   });
 
 
   if (++clientCount < MAX_CLIENTS) {
   if (++clientCount < MAX_CLIENTS) {
-    setTimeout(createClient, CLIENT_CREATION_INTERVAL_IN_MS);
+    setTimeout(createAgent, CLIENT_CREATION_INTERVAL_IN_MS);
   }
   }
 };
 };
 
 
-createClient();
+createAgent();
 
 
 const printReport = () => {
 const printReport = () => {
   const now = new Date().getTime();
   const now = new Date().getTime();