简体   繁体   English

nodejs-集群中的最佳工作程序数

[英]nodejs - optimum number of workers in cluster

When clustering nodejs on a multi-core processor I usually see examples saying - 当在多核处理器上集群化nodejs时, 我通常会看到一些示例,其中包括 -

const numCPUs = require('os').cpus().length;
for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

My questions are - 我的问题是-

  1. If a multi-core processor is running a web app with a reverse proxy terminating ssl (cpu intensive), gzipping (cpu intensive) and doing other stuff + there are other servers doing cpu intensive work of main nodejs server, is it still wise to spawn as many workers as the number of cpu cores (for the main nodejs server)? 如果多核处理器正在运行带有反向代理的Web应用程序,该反向代理终止ssl(cpu密集型),gzipping(cpu密集型)并进行其他工作,还有其他服务器在做主要nodejs服务器的cpu密集型工作,那么这样做仍然明智吗?产生与cpu核心数量一样多的工作人员(对于主要的nodejs服务器)?

  2. What tests should be run to find the optimal number of workers? 应该进行哪些测试以找到最佳工人数量?

  1. You can set an affinity for the process to a set of cores . 您可以将进程的亲和性设置为一组核心

  2. You should have one worker per core available core. 每个核心可用核心应有一个工作线程。 By available core I mean a core that will not be heavily utilized by other processes. 可用内核是指不会被其他进程大量使用的内核。

To ensure everything is fine, your (CPU load / number of cores) should be below 1. 为确保一切正常,您的(CPU load / number of cores)应低于1。

Try to provision your machines with very few distinct services/processes. 尝试为您的机器配置很少的不同服务/流程。 This might seem wasteful at first but it helps MMTD and MMTR for incidents by limiting impact for cascading failures. 乍一看这似乎很浪费,但它通过限制对级联故障的影响来帮助MMTD和MMTR处理事件。

NOTE: this question is usually better asked at Server Fault , another Stack Exchange site. 注意:通常最好在另一个Stack Exchange站点Server Fault上问这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM