Is NodeJS really Single-Threaded?

Filipe Santos picture Filipe Santos · Aug 10, 2011 · Viewed 14.6k times · Source

Node.js solves "One Thread per Connection Problem" by putting the event-based model at its core, using an event loop instead of threads. All the expensive I/O operations are always executed asynchronously with a callback that gets executed when the initiated operation completes.

The Observation IF any Operation occures is handled by multiplexing mechanisms like epoll().

My Question is now:

  • Why doesnt NodeJS Block while using the blocking Systemcalls select/epoll/kqueue?

  • Or isnt NodeJS Single Threaded at all, so that a second Thread is
    necessary to observe all the I/O-Operations with select/epoll/kqueue?

Answer

Femi picture Femi · Aug 10, 2011

NodeJS is evented (2nd line from the website), not single-threaded. It internally handles threading needed to do select/epoll/kqueue handling without the user explicitly having to manage that, but that doesn't mean there is no thread usage within it.