This is my first question of Stack-overflow so please pardon me for any mistake or insufficient information in this question.
So, I am trying to use cluster module of nodeJS for my server and I run nodeJS through my windows machine. I know nodeJS does not have any scheduling policy for cluster module in windows so I have explicitly set the scheduling_policy to rr as mentioned by nodeJS docs. But the problem is when I am trying to keep one worker busy by putting it in an infinite loop; server is not dispatching the request to another worker available and free when we tried to request the server for '/' resource.
Please help me why it is not dispatching the request to other workers.
var cluster=require('cluster');
if(cluster.isMaster){
var cores=require('os').cpus().length;
console.log("Master Cluster setting up :-"+cores+" workers");
for(var i=0;i<cores;i++)
cluster.fork();
cluster.on('online',(worker)=>{
console.log("Worker with Process ID :- "+worker.process.pid+" online");
});
cluster.on('exit',(worker)=>{
console.log("worker "+worker.process.pid+" died...So setting up a new worker");
cluster.fork();
});
}
else{
var app=require('express')();
app.get('/',(req,res)=>{
console.log("Process with pid "+process.pid+" is handling this request");
while(true);
res.write("Yes!");
res.end();
//while(true);
})
app.listen('3000');
}