I am creating a Node.js application for collaborative drawing on an HTML5 canvas. I am using Socket.IO to communicate and I have implemented clustering so I am able to scale my application. My lecturer told me that using clustering is a good idea, but it would not be smart to make every core in the cpu do the same thing, i.e. that defeats the purpose. So in my case it would not be smart to have 8 cores working on the exact same painting, but instead maybe have 8 different paintings, one painting for each core. I also know that Socket.IO only communicates through one core. Right now I am a bit confused on where and how to start. I know that there is this "sticky" socket.io module, but that would just share communication but not make a different painting for each core?
Here is the server I have made:
let http = require('http').Server(application);
let socketIO = require('socket.io')(http);
let cluster = require('cluster');
let cores= require('os').cpus().length;
if (cluster.isMaster) {
for (let i = 0; i < cores; i++) {
cluster.fork();
}
} else {
process.exit();
}
function connect(socket){
socket.on('test',
function emit(data) {
socket.broadcast.emit('test', data);
});
}
socketIO.on('connection', connect);
http.listen(port);