• +91 9723535972
  • info@interviewmaterial.com

NodeJS Interview Questions and Answers

Question - How are worker threads different from clusters?

Answer -

Cluster:

  • There is one process on each CPU with an IPC to communicate.
  • In case we want to have multiple servers accepting HTTP requests via a single port, clusters can be helpful.
  • The processes are spawned in each CPU thus will have separate memory and node instance which further will lead to memory issues.
Worker threads:

  • There is only one process in total with multiple threads.
  • Each thread has one Node instance (one event loop, one JS engine) with most of the APIs accessible.
  • Shares memory with other threads (e.g. SharedArrayBuffer)
  • This can be used for CPU-intensive tasks like processing data or accessing the file system since NodeJS is single-threaded, synchronous tasks can be made more efficient leveraging the worker's threads.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners