Multiple instances of node.js on different kernels

I would like to configure 4 different instances of node.js, each on its own kernel. Is node.js a stack of new instances in a single core, or sets them on new kernels?

Instances are not related to each other and receive requests separately. I would like the processor load to be distributed evenly. I could not find a definitive answer to this question.

+6
source share
2 answers

In general, the system will try to do this on its own to maximize the use of the processor. However, if you want to target a specific processor, you should check the TaskSet . He establishes the affinity of the process.

There are also some useful questions that discuss the same topic. Take a look.

There is also a Cluster module, which can also be very useful for CPU usage. This allows you to develop multiple processes to distribute the load across multiple cores.


UPDATE


Finally, I applied something similar according to the OP.


Case 1


  • I have a dedicated server with 8 processor cores.
  • I deployed a single node thread and used the Cluster module to exchange workload (as described by pl47ypus PS: thanks for its answer).
  • The result is good, but sometimes the child thread may stop responding, so I decided to try the old process that I used in my previous application.

Case 2


  • The same server, I deployed 8 Node.js processes with different ports.
  • Then I put nginx in front of them, listening on port 80 with workflow 8.
  • The result is better than case 1, and also it is very easy to configure nginx, its most stable too.

I also suggest that you simply try some of the solutions mentioned and monitor your system in each case; like processor, memory usage and io. Finally, from your tests you will see the best solution for your use case. Each application has its own requirements, so it's best to try to find what you need.

+7
source

try the following:

var cluster = require('cluster') , numCPUs = require('os').cpus().length; if(cluster.isMaster) { // Fork workers. for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log('worker ' + worker.pid + ' died'); }); return; } 

full code here

look here

0
source

Source: https://habr.com/ru/post/950629/


All Articles