node.js - 异步编程 能解决 CPU密集型计算 的问题吗。
怪我咯
怪我咯 2017-04-17 12:06:20
0
2
614

最近在不断的理解nodejs。

经常看到nodejs不适用于CPU密集型计算的场景,那我们在nodejs中也经常使用异步编程async来执行耗时的查询操作,查询完,再返回就可以了。是不是异步编程来解决CPU密集型计算的问题?

结论:
异步编程是用来解决IO的。
js是单线程,cpu密集型计算还是会耗时。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
巴扎黑

No, you must understand that javascript has only one execution thread. As long as it enters the calculation-intensive area, the CPU will be occupied and the entire program will be stuck here. The reason why io can use asynchronous acceleration is that the CPU is not occupied during the delay period of io.

黄舟

No, asynchronous programming is specifically designed to solve IO-intensive problems. When io is blocked, use asynchronous events to release CPU resources for other tasks.

In essence, asynchronous programming tends to use CPU resources as much as possible, so it is completely meaningless for CPU-intensive programs. . .

Parallel computing and distributed computing should be considered at this time.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template