K
K
kodwi2016-10-23 18:28:38
Node.js
kodwi, 2016-10-23 18:28:38

How to understand Node.js asynchrony principle?

I study node. As I understand it, the application itself plows in one thread. At the same time, for asynchrony, your code must be fired into the event loop using nextTick.
Let's say there are 7 functions for different purposes, all of them do more or less time-consuming work. The code in the main thread uses all of these functions via nextTick. Let's say 5 clients connected at once, i.e. in the event loop'e 7*5 = 35 tasks in the queue.
In short, the question is - is the event loop also executed in one separate thread? If yes, then where will the increase in server performance and decrease in response time to requests come from, if everything is also sequential in loop'e? Explain, please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2016-10-23
@kodwi

The video is already old, but everything is clear
https://youtu.be/w4EHA9xqoNw

S
SagePtr, 2016-10-23
@SagePtr

Due to the fact that threads can perform other asynchronous operations - for example, request the contents of a file and sleep until the disk subsystem gives them this file and pulls the callback. During this time, the next thread from the event loop will be executed.
And if you shove synchronous functions inside these threads, then there will be no performance gain.

I
Ivan Leshchenko, 2016-10-27
@inkluter

Also an old video, but no less relevant.
https://www.youtube.com/watch?v=8aGhZQkoFbQ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question