I just learned that Node.js crown jewel libuv uses blocking system calls for file operations. The asynchronous behavior is implemented with threads! That raises two questions (I only care about Unix):
Most likely to support synchronous operations such as fs.renameSync()
vs fs.rename()
.
It uses a thread pool, as explained in the "Note" at the link you provded.
[...] but invoke these functions in a thread pool and notify watchers registered with the event loop when application interaction is required.
So, it creates a limited number of threads and reuses them as they become available.
Also, regarding the quip of "crown jewel:" Node.js and libuv aren't magic. They're good tools to have at your disposal, but certainly have their limitations.
Though, the hyperbole of "one million file reads" would be a stretch for any platform to manage without constraint.
The same non-blocking API can not be used, as O_NONBLOCK and friends don’t work on regular files! For Linux AIO is available, but it has it’s own quirks (i.e. depends on the filesystem, turns silently blocking for some operations).
I have no idea.
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