Is non-blocking I/O really faster than multi-threaded blocking I/O? How?

后端 未结 9 1330
礼貌的吻别
礼貌的吻别 2020-11-29 15:09

I searched the web on some technical details about blocking I/O and non blocking I/O and I found several people stating that non-blocking I/O would be faster than blocking I

9条回答
  •  盖世英雄少女心
    2020-11-29 15:44

    In Node, multiple threads are being launched, but it's a layer down in the C++ run-time.

    "So Yes NodeJS is single threaded, but this is a half truth, actually it is event-driven and single-threaded with background workers. The main event loop is single-threaded but most of the I/O works run on separate threads, because the I/O APIs in Node.js are asynchronous/non-blocking by design, in order to accommodate the event loop. "

    https://codeburst.io/how-node-js-single-thread-mechanism-work-understanding-event-loop-in-nodejs-230f7440b0ea

    "Node.js is non-blocking which means that all functions ( callbacks ) are delegated to the event loop and they are ( or can be ) executed by different threads. That is handled by Node.js run-time."

    https://itnext.io/multi-threading-and-multi-process-in-node-js-ffa5bb5cde98 

    The "Node is faster because it's non-blocking..." explanation is a bit of marketing and this is a great question. It's efficient and scaleable, but not exactly single threaded.

提交回复
热议问题