About the multiple processes of node.

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?

Aug.13,2021

  1. the number of cores of cpu means the number of processes you can run at the same time, not the processes that you can open at the same time. Check out the operating system
  2. .
  3. involves process scheduling, ditto

problem 1, which refers to processes that exist at the same time.
problem 2, it's hard to analyze jagged packaging performance if you don't list the configuration. I don't know if you have used plug-ins such as happypack, but if it is a relatively simple configuration, the same configuration should not be less than 20 seconds away. the only possible reason is that when you pack, other running applications occupy the resources of the operating system, resulting in slower packaging? This is very complicated to analyze.


with regard to problem 1, I think the process that was executed first exited first. I took a look at it by listening for the close event.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39083-2c154.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39083-2c154.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?