I am running node js and using cluster module. In child process I am creating a websocket server and on websocket connection I am doing console.log(process.pid) on each websocket connection. I even added a loop in worker thread to slow it down which apparently is the case but it is still assigning the same core to each web socket client. I have written a bash script to run my html file which opens concurrent N connections to test if cluster module is working fine. Is this the issue with cluster module or websocket server?
const os = require('os');
const cluster = require('cluster');
if (cluster.isMaster) {
for (let i = 0; i < os.cpus().length; i++) {
cluster.fork();
}
} else {
const server = require('http').createServer(app);
const WebSocket = require('ws');
let ws_clients = {};
const wss = new WebSocket.Server({ server: server});
wss.on('connection', function connection(ws) {
let h = 0;
for (let i = 0; i < 2e10; i++) {
h++;
}
console.log('handled by:', process.pid);
});
}