How Node.js event loop model scales well -


I know that this question has been discussed in the past () but I still understand the node.js incident I've failed the Loop model and a single threaded model how it handles concurrent requests.

Now I understand: we get an Io request-> a thread is internally generated by node.js and io request is assigned -> since it is an io request, so The CPU takes DMA controller and handles this thread-> This thread goes back to the thread pool to make a different request-> DMA is still doing the IO, when the DMA gets all the data Remove from a type of incident This event is captured by the node. Js system and it places the callback function supplied on the event loop - whenever the data received from the event loop is brought to the callback - by IO -> off Thanks to, the callback function only applies to the data received by the callback

This process goes over and over again, please understand someone in my understanding and some Provide information

Only one thread (main thread) is the network I / O (file I / O Working with is a slightly different story because all platforms usable provide asynchronous, non-blocking file I / O APIs, so synchronous file I / O API is used in them in a Threadpool On platforms).

So when the network requests come in, they are all controlled by the main thread which (indirectly) uses epoll / kqueue / IOCP / etc. If data is available (or for example, if there is an incoming TCP connection) (in non-blocked way), if the data is available, then it is necessary to properly call Javascript to pass the socket data. Does. If there is no data on the socket (and there is nothing like this for the event loop, for example the filing timer), then the process of execution for the next trip of the event loop, where the process starts again.

As far as adding socket data to socket javascript objects, it is a combination of C ++ cover objects (eg, etc.) and JavaScript objects that ensure that the data is in the proper place You are on it.

A slightly older diagram that explains what happens in a cycle of the event loop of the node. Some of these nodes may change slightly after v0.9, but this gives you general idea:


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -