Single Thread Mystery - Node
A Single Thread that handles multiple request ?
I have been reading about threads and all the performance gain that you will have if you use multiple threads but there is Node which runs on a single thread. So i tried to investigate how node handles multiple request using a single thread.Event loop Architecture
Node uses an event loop architecture. It specifically uses a non-blocking I/O event model. This means the thread of execution will not block if it is an I/O event. But what is an I/O event for Node ?
Well all http requests, database queries, file manipulation [1]
In my mind i picture node like these (The diagram is based on a typical process structure)
Code - program code
Data - variables of the program
Files - file pointers (I am not sure about if node keeps file pointers at the process level)
After trying to picture this out, several questions pop in to my mind.
How will node be able to utilize a multiprocessor hardware ? Node has "cluster" or you can use several node processes and a load balancer.
The picture above may not be accurate but is able to help wrap my head around Node being single threaded.
Comments