child_process.spawn/exec blocks main thread while spawning child process #9250
Description
Offloading expensive computations to other processes and cores using spawn
or exec
blocks the main thread for significant portions of time. Obviously the spawned process is not blocking node's event loop while it is running, but the act of spawning the process within node seems to be expensive and blocks. When dealing with a high number of concurrent spawns, the major bottleneck is the node event loop blocking while trying to create child processes.
I noticed this by spawning hundreds of concurrent child processes and noting that only 1 CPU core was reaching 90+% utilization. The other cores running the child processes had less than 50% utilization.
Is there a more efficient way to spawn child processes than what is currently done in node? Or is there a way to spawn processes on a background node thread instead of blocking the main thread?