I don't understand several things about nodejs. Every information source says that node.js is more scalable than standard threaded web servers due to the lack of threads locking and context switching, but I wonder, if node.js doesn't use threads how does it handle concurrent requests in parallel? What does event I/O model means?
Node is completely event-driven. Basically the server consists of one thread processing one event after another.
A new request coming in is one kind of event. The server starts processing it and when there is a blocking IO operation, it does not wait until it completes and instead registers a callback function. The
server then immediately starts to process another event (maybe another request). When the IO operation is finished, that is another kind of event, and the server will process it (i.e. continue working on the request) by executing the callback as soon as it has time.So the server never needs to create additional threads or switch between threads, which means it has very little overhead. If you want tomake full use of multiple hardware cores, you just start multiple instances of node.js
This forum thread discusses How nodejs works?. You can join the discussion by clicking on 'Post a reply'. If you are new to Web Developers Forum, you will need to sign up and create a new account.