NodeJS: Parallelism of an Asynchronous Module

I follow the asynchronous module of each method ( https://github.com/caolan/async#each ). He says the method repeats through the array in parallel. β€œ Parallel ” is a word that bothers me. AFAIK, now JavaScript can execute code in parallel, because it has a single-threaded model.

The examples shown in each method focus on I / O scenarios. I use the "each" method only to add array numbers. If parallelism exists, can I prove this with my example?

Thank you for reading.

+4
source share
2 answers

The "parallel" in the asynchronous documentation does not refer to the "parallel" in terms of concurrency (for example, to several processes or threads executed simultaneously), but "parallel" in terms of other actions independent of each step (the opposite operation will be eachSeries , where each step It starts only after the previous one is completed).

The parallel version makes sense only if the steps perform some kind of input-output, which (due to the asynchronous nature of Node) can be executed in parallel to each other: if one step has to wait for the input-output, other steps can happily continue to send / receive data.

If the steps are mostly cpu related (i.e. doing a lot of computation), this will not give you any better performance, because, as you say, Node runs the interpreter in a single thread, and this is not something that async changing.

+3
source

As robertklep said, it is more parallel, not parallel. You won’t achieve a big performance boost by computing heavy code in parallel. This is useful when you have to do parallel I / O (for example, communicating with an external web service for all elements of an array).

+1
source

All Articles