I was wondering if it makes sense to add the cluster package to a node application deployed using kubernetes requiring one or less cores.
When using the cluster package we usually do something like this:
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
masterProcess();
} else {
childProcess();
}
function masterProcess() {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < numCPUs; i++) {
console.log(`Forking process number ${i}...`);
cluster.fork();
}
process.exit();
}
function childProcess() {
console.log(`Worker ${process.pid} started and finished`);
process.exit();
}
But it wouldn't make sense to me to use that with say
resources:
limits:
cpu: "1"
requests:
cpu: "0.5"
since kubernetes will limit the application cpu time any ways, even when using multiple workers. Does that make sense?
I haven't tried this with a load yet.
Well, since you’re using containers, there is really no need to use the cluster module. Just spin a new container and distribute load using a load balancer like Nginx. I hope this helps.