When I call .spawn to make a new child process in Node.js, does this take advantage of multi-core CPUs?
Reference: https://nodejs.org/api/child_process.html
NodeJS uses Javascript to develop server side applications and shares the same behavior. It runs on one CPU core regardless of how many CPU cores you have in your machine or a virtual machine in the cloud.
Usually, Node. js allows single-threaded, non-blocking performance but running a single thread in a CPU cannot handle increasing workload hence the child_process module can be used to spawn child processes. The child processes communicate with each other using a built-in messaging system.
Not many realize that NodeJS runs in a single thread by default. Besides, it utilizes only one CPU core for this thread. So, for example, if you're using a 4 core machine, Node will only be using a single core.
Generally, if the child process or cluster modules are not involved, then there is no benefit from having multiple cores on your system, because Node. js will only use one core. One example of a single-threaded application would be a simple HTTP server like the following: http.
Yes, a new process will be created and managed by your OS. That new process can be executed in parallel to the main process as long as your computer has at least 2 virtual CPU cores.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With