Is NodeJS really Single-Threaded?

MultithreadingArchitecturenode.js

Multithreading Problem Overview


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 occurs is handled by multiplexing mechanisms like epoll().

My question is now:

  • Why doesn't NodeJS block while using the blocking Systemcalls select/epoll/kqueue?

  • Or isn't NodeJS single threaded at all, so that a second Thread is
    necessary to observe all the I/O-Operations with select/epoll/kqueue?

Multithreading Solutions


Solution 1 - Multithreading

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.

Solution 2 - Multithreading

No.

When I/O operations are initiated they are delegated to libuv, which manages the request using its own (multi-threaded, asynchronous) environment. libuv announces the completion of I/O operations, allowing any callbacks waiting on this event to be re-introduced to the main V8 thread for execution.

V8 -> Delegate I/O (libuv) -> Thread pool -> Multi threaded async

Solution 3 - Multithreading

JavaScript is single threaded, so is event-model. But Node stack is not single-threaded.

Node utilizes V8 engine for concurrency.

Solution 4 - Multithreading

No Nodejs in the whole is not single-threaded, but Node-Event loop (which nodeJS heavily uses) is single-threaded

Some of the node framework/Std Lib are not single-threaded

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFilipe SantosView Question on Stackoverflow
Solution 1 - MultithreadingFemiView Answer on Stackoverflow
Solution 2 - MultithreadingserkanView Answer on Stackoverflow
Solution 3 - MultithreadingPujanView Answer on Stackoverflow
Solution 4 - MultithreadingyaswanthkoneriView Answer on Stackoverflow