简体   繁体   English

Node.js集群模块:与其他进程共享核心而不会重叠

[英]Node.js cluster module: sharing cores with other processes without overlap

Suppose I have a 16 core machine and I want a Node.js webserver to use 8 cores, and I want a Java REST/API server to use the other 8. The idea being that Node would be making API calls over localhost, even though the API server may handle requests coming from elsewhere. 假设我有一台16核的机器,并且我想让一个Node.js Web服务器使用8个核,并且我想让Java REST / API服务器使用其他8个核。这个想法是,即使该节点将通过本地主机进行API调用,即使API服务器可能会处理来自其他地方的请求。

I'm using Node's cluster module to accomplish this; 我正在使用Node的集群模块来完成此任务; basically, doing cluster.fork() 8x. 基本上,执行cluster.fork() 8x。 I assume Java has its own ways of utilizing X cores, but others are writing that piece of software. 我认为Java有使用X内核的自己的方式,但是其他人正在编写该软件。

Is there anything I need to do, from a node perspective, to ensure that my code doesn't run on any of the same cores Java is running on? 从节点的角度来看,我有什么需要做的,以确保我的代码不会在Java正在运行的任何相同内核上运行? It seems simple enough to run fork() n/2 times, where n = numCpus, and if that's all I need to worry about, great, but I wanted to ask this question to make sure I'm not missing something important. 运行fork() n / 2次似乎很简单,其中n = numCpus,如果这就是我所要担心的,那太好了,但是我想问这个问题以确保我没有错过任何重要的事情。

It is up the the kernel scheduler to manage this, but you can potentially give the kernel some hints by setting the processor affinity . 这是内核调度程序来管理的,但是您可以通过设置处理器亲和力来给内核一些提示。 For example, on linux, you might be able to use taskset to set process affinity for each of the started processes. 例如,在Linux上,您可能能够使用taskset集为每个已启动的进程设置进程亲和力。

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

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