为什么node.js不适合繁重的CPU应用? [英] Why is node.js not suitable for heavy CPU apps?

查看:113
本文介绍了为什么node.js不适合繁重的CPU应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Node.js服务器在I / O和大量客户端连接方面非常有效。但是,与传统的多线程服务器相比,为什么node.js不适合繁重的CPU应用?

Node.js servers are very efficient concerning I/O and large number of client connection. But why is node.js not suitable for heavy CPU apps in comparison to a traditional multithreading server?

我在这里读到了 Felix Baumgarten

推荐答案

Node尽管有异步事件模型,本质上是单线程的。启动节点进程时,您正在单个核心上运行单个线程的单个进程。因此,代码不会并行执行,只有I / O操作是并行的,因为它们是异步执行的。因此,长时间运行的CPU任务将阻塞整个服务器并且通常是一个坏主意。

Node is, despite its asynchronous event model, by nature single threaded. When you launch a Node process, you are running a single process with a single thread on a single core. So your code will not be executed in parallel, only I/O operations are parallel because they are executed asynchronous. As such, long running CPU tasks will block the whole server and are usually a bad idea.

鉴于你刚刚启动这样的Node进程,它可能有但是,多个Node进程并行运行。这样,您仍然可以从多线程体系结构中受益,尽管单个Node进程没有。您只需要在前面安装一些负载均衡器,以便在所有Node进程中分配请求。

Given that you just start a Node process like that, it is possible to have multiple Node processes running in parallel though. That way you could still benefit from your multithreading architecture, although a single Node process does not. You would just need to have some load balancer in front that distributes requests along all your Node processes.

另一个选择是让CPU在不同的进程中工作并创建Node与那些人互动而不是自己做工作。

Another option would be to have the CPU work in separate processes and make Node interact with those instead of doing the work itself.

阅读相关内容:

  • Node.js and CPU intensive requests
  • Understanding the node.js event loop

这篇关于为什么node.js不适合繁重的CPU应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆