0

I have a node process that runs tasks. When I run an intensive task, in top it can show more than 100% CPU usage (around 110%). From some research that I was doing, I figured that nodejs was single-threaded meaning it would only be running on one CPU per process.

Is it possible that the workload could take up the whole CPU so it moves some of the load to another CPU? Was unable to find a clear answer on this.

pythonNovice
  • 1,130
  • 1
  • 14
  • 36
  • The V8 engine that Node.js uses is single-threaded. NodeJs Itself, I don't think, is single-threaded, else, how would microtask queue and other related APIs work? – Anuraag Barde Jan 04 '23 at 19:02

1 Answers1

1

Other than specifically coding with WorkerThreads (which it doesn't sound like you are using), nodejs runs your Javascript code in only a single thread (e.g. the interpreter itself just uses one thread to run Javascript opcodes).

But, nodejs does have other threads that are used in the implementation of library functions such as file system operations and crypto operations and for the garbage collector. And, some 3rd party libraries may use native threads in their own implementation. So, it is definitely possible for nodejs to use more than just one core. It really depends upon what the code/task is doing and what library functions are being called.

Is it possible that the workload could take up the whole CPU so it moves some of the load to another CPU?

It does not move the running of your Javascript to another CPU. But as I said above, some library functions that use native code may use additional threads.

jfriend00
  • 683,504
  • 96
  • 985
  • 979