简体   繁体   English

node.js的缺点?

[英]Downside of node.js?

Disclaimer, my knowledge of node.js a few articles mostly summarized by this http://en.wikipedia.org/wiki/Node.js 免责声明,我对node.js的了解几篇文章主要由http://en.wikipedia.org/wiki/Node.js总结

That said, so my understanding is that it's supposed to be very quick because it avoids the overhead of threading. 就是说,所以我的理解是它应该很快,因为它避免了线程的开销。 It puts everything into a single loop instead of doing the overhead of switching between processes. 它将所有内容置于一个循环中,而不是进行进程之间切换的开销。

I assume there is a reason why there is a sophisticated method of switching contexts completely in between threads. 我认为有一个原因,为什么有一种复杂的方法可以在线程之间完全切换上下文。 My question is, what is the benefit of having threads over the node.js approach? 我的问题是,与node.js方法相比,拥有线程有什么好处?

Node.js is extremely fast with IO-intensive tasks, since its event model supports IO delays perfectly. Node.js在处理IO密集型任务时非常快,因为它的事件模型完美支持IO延迟。 On the other hand, it is completely incapable of doing CPU-intensive tasks without stopping everything. 另一方面,它完全无法执行CPU密集型任务而不停止所有操作。 Thus, if you need some heavy calculation, you will want to fork off a worker to do it for you. 因此,如果您需要进行繁重的计算,则需要派遣一名工人为您完成这项工作。

Threaded model switches contexts automatically, whatever the thread is doing, and thus can handle CPU-intensive jobs without impacting other threads negatively too much. 无论线程在做什么,线程模型都会自动切换上下文,因此可以处理CPU密集型作业,而不会对其他线程造成太大的负面影响。 (Or rather, they will still work, only slower if CPU capacity is reached.) (或者说,它们仍然可以工作,只有在达到CPU容量时才更慢。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM