-1

I am new to node.js. What I understand about it is that it is single threaded. It uses one thread. Now if I have a CPU 6 cores or 12 threads it will only use 1 thread. What will happen to other 11 threads? Are they useless with node.js?

Hasnain Ali
  • 5
  • 1
  • 7

1 Answers1

0

Yes, unless you use:

  • some functions from child_process module like spawn
  • the (no more so) new module worker_threads

If you have one server with only one node.js instance, you don't need more than 2 CPU:

  • one for the node.js instance
  • one for the libuv thread pool (I/O mainly)

Consider that this is an estimation, all depends on the SO, because also the SO need the CPU sometimes of course.

You can do also fine-tuning to assign a CPU to the node.js core (linux affinity ) but the benefit could be really hard to measure.

If you have other software in the server, or you run multiple node instances, of course, more CPU will execute more operations.

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73