Thread in an event-driven vs non-event driven web server

后端 未结 2 1648
滥情空心
滥情空心 2021-01-31 06:17

The following two diagrams are my understanding on how threads work in a event-driven web server (like Node.js + JavaScript) compared to a non-event driven web server (like IIS

2条回答
  •  情歌与酒
    2021-01-31 07:13

    1. Node may use threads for IO. The JS code runs in a single thread, but all the IO requests are running in parallel threads. If you want some JS code to run in parallel threads, use thread-a-gogo or some other packages out there which mitigate that behaviour.

    2. Same as 1., threads are created by Node for IO operations.

    3. You don't have to handle threading, unless you want to. Easier to develop. At least that's my point of view.

    4. A node application can be coded to run like another web server. Typically, JS code runs in a single thread, but there are ways to make it behave differently.

    Personally, I recommend threads-a-gogo (the package name isn't that revealing, but it is easy to use) if you want to experiment with threads. It's faster. Node also supports multiple processes, you may run a completely separate process if you also want to try that out.

提交回复
热议问题