Node.js child_process.fork () to run on different CPU cores

I have an application that runs lengthy processes. To make it faster, I make a simple outline of the data and want to run it in parallel, simply using the .fork () 2 instance of the same application.

I have a machine with two cores, and I want to make sure that 2 cores are used and the first instance runs on the first core, the second on the second core.

I know about the cluster module, but in this case it seems to be irrelevant, since I do not need HTTP services and load balancing between them. They’re just workers (which means they don’t need to communicate with each other, send messages or anything else - they just perform HTTP requests and store data in a database).

Is it even possible to control which processor core the node.js process would run? How to track this on Mac / Linux?

+7
multiprocessing fork
source share
2 answers

The cluster module is exactly what you need: http://nodejs.org/api/cluster.html

+2
source share

You want this, which is a specific part of the cluster API:

 cluster.setupMaster([settings]) 

https://nodejs.org/api/cluster.html#cluster_cluster_setupmaster_settings

I also wrote a module to do this, and there are a few:

https://www.npmjs.com/package/poolio

my module works well, but the API is not so simple, so I would recommend using the main module

0
source share

All Articles