I am trying to create one application using nodejs socket.io with version 4.
I am using very simple script that is accepting a connection and send a JSON dummy ({"abc":"abc"}) payload on an event(say 'loaddata' event) into a socket room which is created on event call(if it is not already created).
While benchmarking, if i try to make 1000 connections with 100 common subscription(100 rooms), then it starts giving disconnection error of few socket connections after few seconds.
Server(where socket code is running) Machine details : 8cpu,8Gb RAM.
After TOP command usage, it seems , CPU is over 100% when i shoot 1000 connections in a go with 100 subscription each.
is there some limitation in socket.io or i am doing some mistake or is this is the max limit for socket.io with this conn number. ?
//Server code : const app = require('express')();const server = require('http').Server(app);const { Server} = require("socket.io");const io = new Server(server, { path: '/abc', transports: ['websocket']})io.on('connection', async (socket) => { socket.emit('broadcast', `Welcome to StreamerIO `) socket.on('dataload', (data) => { socket.join('datafeed_'+ data.token); sendFeed('datafeed_'+ data.token); });});const sendFeed = (room) => { io.to(room).emit("getdata", {"abc": "abc" });}server.listen("7005", () => { console.log(`Socket Server listening on ${server.address().address}:${server.address().port}`);});//Client Code :const io = require("socket.io-client");const connectFeed = async (subscription, tokens_list) => { const socket = io('ws://localhost:7005/', { path: "/abc", transports: ['websocket'] }); socket.on("connect", () => { function subscribetoken() { if (socket.connected) { if (tokens_list && tokens_list.length) { tokens_list.forEach(token => { socket.emit("dataload", { token: token }); }); } } } function pingpong() { socket.emit("3"); } setTimeout(subscribetoken, 1000) setInterval(pingpong, 1000) }); socket.on('getdata', function(message) { console.log("received data"); });}const startBenchMarking = (connections, subscription, tokens_list) => { var runConnections = () => { for (let i = 1; i <= connections; i++) { connectFeed(subscription, tokens_list) } } runConnections();}const NO_OF_CONNECTIONS = 1000;const NO_OF_SUBSCRIPTIONS = 100;const activetokens = ["a|1", "a|2", "a|3", ........] // an array of 100 diff tokens. startBenchMarking(NO_OF_CONNECTIONS, NO_OF_SUBSCRIPTIONS, activetokens);
i tried running above scripts with diff no of connections. it is running fine with upto 950 connections. and getting disconnections problem when connections crosses 1000+.
expecting : is there some limitation in socket.io or i am doing some mistake or is this is the max limit for socket.io with this conn number. ?