[英]Does it make sense to use NodeJS cluster package with Kubernetes?
I was wondering if it makes sense to add the cluster package to a node application deployed using kubernetes requiring one or less cores. 我想知道是否可以将集群程序包添加到使用需要一个或更少内核的kubernetes部署的节点应用程序中。
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. 因为kubernetes会以任何方式限制应用程序cpu时间,即使使用多个工作程序也是如此。 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. 只需旋转一个新容器并使用Nginx等负载平衡器分配负载即可。 I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.