Book Image

Node.js High Performance

By : Diogo Resende
Book Image

Node.js High Performance

By: Diogo Resende

Overview of this book

Table of Contents (14 chapters)

The I/O library


The library used by Node.js to be able to perform asynchronous I/O operations across multiple platform environments is libuv. This is an open source library. Actually, It is used by platforms to provide similar functionality to other languages such as Luvit and Lua. Libuv is a cross-platform library that uses the best possible methods for each platform to achieve the best I/O performance and still exposes a common API.

This library is responsible for network tasks (TCP and UDP sockets), DNS requests, filesystem operations, and much more. It's the library that accesses files, lists directory contents, listens for socket connections, and executes child processes. The following image shows how Node.js uses V8 and libuv at the same level:

You can see that libuv does not depend on V8 to interact with I/O. It's a C library with its own thread pool. This thread pool is designed to be fast and avoid creating and destroying task threads too often, as they're very expensive. The library...