Internals of node.js. How does it actually work

前端 未结 2 681
攒了一身酷
攒了一身酷 2020-12-25 14:08

Perhaps somebody who implemented node.js module can explain the protocol between node.js queue processed on a single thread and a blocking IO operations that will be perform

相关标签:
2条回答
  • 2020-12-25 14:51

    I highly suspect that Node.JS goes the same route as Twisted and uses only non-blocking IO and greenlets. OS threads seem pretty inefficient for this sort of thing.

    0 讨论(0)
  • 2020-12-25 15:05

    Node.js doesn't really manage any of this quite as you speculated. It instead relies on the OSs to do most of the async IO. It uses select/epoll/kqueue depending on the operating system. "They" just put a call out and the OS calls back with a stream, chunks, etc... As far as the evented portion of it, this is built into V8, it does all the work tieing callbacks to specific events same as it does in the browser. Finally, you can look into libuv, which was written along with node and is now all maintained by Joyent. It's open source on Github so you can browse through the code if you really want the details =D

    0 讨论(0)
提交回复
热议问题