Skip to content

Rough proof-of-concept of using aio_read for fs.readFile()

Notifications You must be signed in to change notification settings

zbjornson/node-aio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This demonstrates using aio_read(3) (posix) for an implementation of fs.readFile().

The libuv docs cite this article as the reasoning behind using read() in a loop instead of using async file operations. The major issue that stands out is that notifications can only be issued using a signal or in a new thread. As a workaround, this demo polls the status of an aio_read() request in the event loop. This prevents the majority of the blocking of the event loop because aio_error(3) is fast.

Note that this demo still uses the threadpool for fopen and fstat to avoid blocking as much as possible. (nit: aio_read() could be issued in the event loop to avoid that small block.)

Benchmark (time to read a 16 MB file 50 times):
Node.js v10.x's chunked fs.readFile(): 4714 ms
Approximation of Node.js v8.x's one-shot fs.readFile(): 366 ms
This module: 489 ms

About

Rough proof-of-concept of using aio_read for fs.readFile()

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published