Grasping the Node JS alternative to multithreading

后端 未结 5 1111
慢半拍i
慢半拍i 2020-11-28 18:58

If I understand correctly Node JS is non blocking...so instead of waiting for a response from a database or other process it moved on to something else and checks back later

5条回答
  •  伪装坚强ぢ
    2020-11-28 19:56

    Yes, I'd say that your understanding is entirely correct. This article (archived) explains the rationale behind this design quite well. This is probably the most important paragraph:

    Apache is multithreaded: it spawns a thread per request (or process, it depends on the conf). You can see how that overhead eats up memory as the number of concurrent connections increases and more threads are needed to serve multiple simulataneous clients. Nginx and Node.js are not multithreaded, because threads and processes carry a heavy memory cost. They are single-threaded, but event-based. This eliminates the overhead created by thousands of threads/processes by handling many connections in a single thread.

提交回复
热议问题