DEV Community

Discussion on: Is Node.js Single-Threaded or Multi-Threaded? and Why?

Collapse
 
arealesramirez profile image
Andres Reales

Thanks for complementing.

As per my understanding, worker_threads will share memory but each will have each own independent event loop.

Collapse
 
metcoder profile image
Carlos Fuentes

Kinda, the worker thread can share memory with other threads (made out of the same parent thread) or the parent thread itself. But they just create a new instance of the V8 engine, not another full Node process (where the Node process is who instantiate the event_loop). In Contrast, Cluster in fact instantiates one or more new Node process, for instance they come with it's own event_loop :)

Thread Thread
 
arealesramirez profile image
Andres Reales

Oh yeah! I see what you mean. Using pm2 is a good implementation of clusters where we could have a node per each core of the cpu.
Thanks for the clarifying about the event loop!

Thread Thread
 
metcoder profile image
Carlos Fuentes

Exactly! 😄
No worries, happy to help! As I said, great work ;)