OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Nodejs Socket.io v4 disconnection problem on 1000 connections with 100 subscription each

  • Thread starter Thread starter RahulRV
  • Start date Start date
R

RahulRV

Guest
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. ?

Code:
//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. ?

<p>I am trying to create one application using nodejs socket.io with version 4.</p>
<p>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).</p>
<p>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.</p>
<p>Server(where socket code is running) Machine details : 8cpu,8Gb RAM.</p>
<p>After TOP command usage, it seems , CPU is over 100% when i shoot 1000 connections in a go with 100 subscription each.</p>
<p>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. ?</p>
<pre><code>//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);
</code></pre>
<p>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+.</p>
<p>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. ?</p>
 

Latest posts

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top