What happens when a single request takes a long time with these non-blocking I/O servers?

前端 未结 6 1054
北恋
北恋 2021-01-12 00:59

With Node.js, or eventlet or any other non-blocking server, what happens when a given request takes long, does it then block all other requests?

Example, a request c

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 01:08

    Everything in node.js runs in parallel internally. However, your own code runs strictly serially. If you sleep for a second in node.js, the server sleeps for a second. It's not suitable for requests that require a lot of computation. I/O is parallel, and your code does I/O through callbacks (so your code is not running while waiting for the I/O).

    On most modern platforms, node.js does us threads for I/O. It uses libev, which uses threads where that works best on the platform.

提交回复
热议问题