Вопрос

Node has a async/sync versions of all its filesystem IO operations, but I was wondering: how is async file IO implemented in Node.js for operations on local files? I myself was messing around with libevent, which uses the reactor pattern, like Node, but I read that using evented IO on local files is pointless, because they will always be readable and writable, so they'll be operated upon instantly.

If this is true, what are the differences between these methods, at least for local files?

Это было полезно?

Решение

Look at "the cost of I/O" table in "understanding node.js io loop" article. Local file IO is not instant. Internally it is implemented using blocking file operations and libuv thread pool on systems where async file api is not available (Linux) and using kernel-level async calls where available (for example, IOCP on Windows).

I have not seen benchmarks of sync vs async file io on different systems, but it worth knowing that thread pool dispatching does add some penalty and usually pool size correspond to number of CPUs which is good for cpu-bound async tasks but may not be optimal for async file IO emulation.

My guess is that on average even thread pool based async FS would result in better server latency/responsiveness compared to sync versions, especially on big files.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top