简体   繁体   English

在Kubernetes中使用NodeJS集群软件包有意义吗?

[英]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.

相关问题 缩小 NodeJS 中使用的代码有意义吗? - Does it make sense to minify code used in NodeJS? 在水平缩放的云环境中使用节点的“集群”是否有意义? - Does it make sense to use node's `cluster` in horizontally-scaled cloud environment? 什么时候使用ADF有意义? - When does it make sense to use ADF? 在同一个 Kubernetes 节点上多次复制 Node.js Kubernetes 服务器 pod 是否有意义? - Does it make sense to replicate a Node.js Kubernetes server pod many times on the same Kubernetes node? NodeJS 的“https”package 是否使“http”变得多余? - Does “https” package of NodeJS make “http” redundant? 为什么为Redis使用异步客户端是有意义的? - Why does it make sense to use asynchronous clients for Redis? 何时将数据库用于作业队列是有意义的? - When does it make sense to use a database for a job queue? NodeJS:如果我在请求结束时将mysql数据返回给客户端,是否意味着回调没有意义? - NodeJS: if I return mysql data to client in the end of request does it mean that having callbacks doesn't make sense? 当在nodejs中使用集群和winston时,日志的maxsize不起作用 - when use the cluster and winston in nodejs ,the log's maxsize does not work 从Nodejs访问kubernetes集群API - Access kubernetes cluster API from Nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM