greim
greim

Reputation: 9437

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.

I'm using Node's cluster module to accomplish this; basically, doing cluster.fork() 8x. I assume Java has its own ways of utilizing X cores, but others are writing that piece of software.

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? 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.

Upvotes: 0

Views: 120

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161457

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.

Upvotes: 1

Related Questions