美文网首页我爱编程
Node.js event loop

Node.js event loop

作者: SummerDreamEve | 来源:发表于2018-06-10 00:33 被阅读0次

参考http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/

image.png

1.The first basic thesis of node.js is that I/O is expensive

synchronous:

you handle one request at a time, each in turn. pros: simple cons: any one request can hold up all the other requests

fork a new process

you start a new process to handle each request. pros: easy cons: does not scale well, hundreds of connections means hundreds of processes. fork() is the Unix programmer's hammer. Because it's available, every problem looks like a nail. It's usually overkill

threads

start a new thread to handle each request. pros: easy, and kinder to the kernel than using fork, since threads usually have much less overhead cons: your machine may not have threads, and threaded programming can get very complicated very fast, with worries about controlling access to shared resources.

2. The second basis thesis is that thread-per-connection is memory-expensive

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.

相关文章

网友评论

    本文标题:Node.js event loop

    本文链接:https://www.haomeiwen.com/subject/ckoxeftx.html