Libuv Uses Blocking Internal File System Calls - Why? How?

I just found out that Node.js crown jewel libuv uses system lock calls for file operations . Asynchronous behavior is implemented using threads! This raises two questions (I only care about Unix):

  • Why doesn't he use non-blocking file system calls, for example, for networks?
  • If there are a million outstanding files, it probably won't start a million threads ... What does libuv do?
+4
source share
2 answers
  • The same non-blocking API cannot be used, since O_NONBLOCK and friends do not work with regular files! For Linux, AIO is available, but it has its own quirks (that is, it depends on the file system and is automatically disabled for some operations).

  • I have no idea.

+2
source
  • Most likely, synchronous operations such as fs.renameSync()vs will be supported fs.rename().

  • It uses the thread pool, as described in the "Note" link, which you presented.

    [...] but call these functions in the thread pool and notify observers registered in the event loop when interaction with the application is required.

    Thus, it creates a limited number of threads and reuses them as they appear.

, " :" Node.js libuv . , , , .

" " .

+5

All Articles