Sign in
Log inSign up
Is Node.js truly non-blocking?

Is Node.js truly non-blocking?

Jaydip Manasuriya's photo
Jaydip Manasuriya
·Feb 24, 2016

Node is using event-loop and single threaded approach in contrast to traditional threaded model used by other server side stacks.

In traditional threaded model, each client request is served by a new thread or process. In node it assigns a new thread from it's limited thread pool if the request requires I/O like DB access or some other blocking task and on completion of the task thread hand over the result with control to node's event-loop.

It is clear that for parallel execution of blocking tasks node uses threads with the help of libuv and event-loop.

My confusion is, let say my application has all the client requests having some sort of blocking task like DB access or some sort of File System access that needs a separate thread from node's single thread of execution. If node's thread pool is having m threads and concurrent requests become m+1, will node still serve more requests without new requests waiting for threads from pool become free to serve?

Here comparing this scenario with threaded model looks like node's single threaded model is only advantageous when there are some non-blocking requests along with some simple computation intensive requests.

It is possible to use multi-core CPU to increase OS capabilities using node's "cluster" module but I am only considering single core CPU.

Correct me if anything is wrong with my understanding.

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct