I am learning Node.js
I have found this note on libuv official documentation-
“ libuv
uses a thread pool
to make asynchronous file I/O
operations possible, but network I/O
is always performed in a single thread, each loop’s thread.”
My question is for below statement(from an unofficial resource) -
"Today’s operating systems already provide asynchronous interfaces for many I/O tasks (e.g. AIO on Linux). Whenever possible, libuv will use those asynchronous interfaces, avoiding usage of the thread pool."
-- is this Statement true for asynchronous file I/O operations
or only applicable for Network I/O
?
For some standard library function calls, the node C++ side and libuv decide to do expensive calculations outside of the event loop entirely.They make something called a thread pool that thread pool is a series of four threads that can be used for running computationally intensive tasks such as hashing functions or reading files in hard drive(fs module functions). There are ONLY FOUR things that use the thread pool - DNS lookup, fs, crypto and zlib.
So just as the node standard library has some functions that make use of libuv thread pool it also has some functions that make use of code that is built into the underlying operating system through libuv. Neither libuv nor node has any code to handle all of this low level network request operations. Instead libuv delegates the request making to the underlying operating system. So it's actually our operating system that does the real network requests. Libuv is used to issue the request and then it just waits on the operating system to emit a signal that some response has come back to the request. Network I/O is done by network hardware in your system and ISP.OS just keeps tracking of connections and once I/O operations done OS will pass the results to Libuv.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With