5

It is known that node.js internally handles asynchronous calls and the programmer never needs to care about what is going on in the backstage. As far as I know, even if everyone says that node.js is only single thread, internally v8/libuv libraries are spawning threads to handle the execution of the async fragments of the program.

My question is if those threads are spawned, are they scaling the multicore architectures? I mean If I have a cpu with 4 cores and my main node thread is running on one of those CPU's, will those internally spawned threads scale to the other three CPU's and not remain on the same CPU. Theoretically they should scale but since everyone says node.js out-of-box is not using multiple cores, I thought this is worth asking.

1 Answer 1

1

Node.js deals with one-thread-per-process. To make it scale out to multiple cores, you need to run multiple Node.js servers, one per core and split request traffic between them.

Sign up to request clarification or add additional context in comments.

4 Comments

one-thread-per-process : I don't think that this phrase is understood correctly. There is one process (node process) and it's thread (main node thread) but more threads are spawned during the process to handle async calls. Why would anyone require a thread library like v8 and libuv if everything is handled with only one thread?
Node.js works on only single thread of execution which actually means that it do execute everything by single thread based on event loops. If you want node.js to use multiple cores of single processor, then go with clusters.
Also,v8 provides strong multithreaded environment so dont mix it with multiple core
Thanks for the responses @Pragya but still I am not satisfied with the answer. Multi-threaded environments naturally implies that those threads may/can run on different cores available on the CPU. If node.js works on one single thread all the time and all the time, how the async calls are possible without execution being blocked. If main thread is executing all those async fragments than how the system is able to listen to new connections for example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.