Bharath
Bharath

Reputation: 25

Node JS I/O threads

If Node JS also uses a I/O thread in libuv to perform IO, how is that thread different from a thread created by IIS when it receives request for simple I/O?

Upvotes: 0

Views: 266

Answers (1)

Gireesh Punathil
Gireesh Punathil

Reputation: 1374

  • Node.js does not use separate thread(s) for I/O. It multiplexes the single thread between many tasks.

  • At high level, I/O is divided into 2: n/w IO and disc IO. While the former has buffering mechanism at kernel level, node.js manages the IO in a completely asynchronous model - meaning the data is processed when the kernel buffers are absolutely ready to reciprocate the operation in a fully non-blocking mode. Disc IO still involves blocking sequences, so ndoe.js employs libuv worker threads to simulate asynchronous IO. In either ways, there is no blocking code anywhere.

  • libuv threads are pre-created and fixed in number, so there is no runtime overhead of using them.

Hope this helps.

Upvotes: 2

Related Questions