J
J
jtag2019-07-13 09:19:28
Node.js
jtag, 2019-07-13 09:19:28

How to distribute child processes across all cores?

At the beginning of the script, the number of child processes corresponding to the number of addresses is created, how can they be evenly launched on all processor cores?

const cp = require('child_process');
    let result = ["192.168.1.10", "192.168.1.11", "192.168.1.12"];
    let children = [];
    for(let i = 0; i<result.length; i++) {  
        children[i] = cp.fork(`server.js`);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2019-07-13
@bingo347

If linux, then taskset
On other kernels (BSD, Darwin, WinNT), you need to google analogues
In general, it makes little sense to become attached to specific kernels, your process is not the only one in the system, why not entrust the distribution of kernels to the OS itself? switch-context will still be, because in addition to your 3 processes there will be several hundred others, not to mention the fact that many of them are multi-threaded.
And here's something to think about, the node is not so single-threaded. In addition to 1 v8 thread (and starting from node 10 there can be several ), you have from 4 to 128 libuv threads (because the network can work asynchronously, but with the file system, you have to emulate asynchrony on streams). There may also be C++ addons that spawn their own threads. And is it worth tying all this goodness to 1 single core?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question