Source of the problem: because the packing time of webpack is a little different each time, and sometimes the time difference between the two packages is quite large, so I want to package items with the same webpack configuration at the same time through multiple processes of node and take an average. (I want to do a comparison on different webpack configurations to optimize performance)
-
question 1: how many processes can node.js open at a time
- looking at the relevant data, I come to a conclusion: the number of processes that node can open depends on the number of cores of cpu, so I have come to the conclusion that theoretically node can only open 4 processes at a time (in the case of cpu 4 cores)
- but I execute
require ("child_process"). Fork (". / child.js")
through a for loop. When I loop 10 times, I get 10 different processes for pid, as follows:
// index.js
const childProcess = require("child_process");
for (let i = 0; i < 10; PPi) {
childProcess.fork("./child.js");
}
// child.js
console.log("Worker-" + process.pid + ": Hello world.")
// output
Worker-91432: Hello world.
Worker-91433: Hello world.
Worker-91434: Hello world.
Worker-91437: Hello world.
Worker-91435: Hello world.
Worker-91441: Hello world.
Worker-91436: Hello world.
Worker-91439: Hello world.
Worker-91440: Hello world.
Worker-91438: Hello world.
- question 2: why the time of each webpack package varies a lot in the same configuration, sometimes by more than 20 seconds
ask for advice?