使用 v8 和 node.js 的多处理器

发布于 2024-09-29 20:39:59 字数 105 浏览 0 评论 0原文

我读到 V8 不是多线程的,并且不可能是设计的。

这是真的吗?我真的可以优化脚本以并发运行(在 Node.js 上),但并发性无法扩展到多个处理器吗?我认为这是并发设计的主要原因。

I was reading that V8 isn't multithreaded, and can't be by design.

Is this true? Is it really the case that I can have a script optimized to run concurrently (on node.js) but that concurrency can't extend to multiple processors? I kinda thought that was a major reason for a concurrent design.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凡间太子 2024-10-06 20:39:59

For Node v0.8 and above, the https://github.com/audreyt/node-webworker-threads module now provides the same Web Worker API, implemented with native threads aimed for multi-core scheduling, with lower serialization & worker creation overhead compared to process-based node-worker module.

甜味拾荒者 2024-10-06 20:39:59

对于node.js来说,它不是并发的,而是异步的。 Node.js 中只有一个线程和一个事件循环来处理所有 IO。

Node.js 中有一些用于并发的工具,它们主要围绕多个进程进行。但与所有 Node.js 一样,它们正处于开发的早期阶段。例如,您可以使用 fugue 管理多个工作进程,也可以使用可能熟悉的 Web Workers API 使用 节点worker

As for node.js, it's not concurrent but asynchronous. There's a single thread, and a single event loop, that handles all IO in node.js.

There are some tools for concurrency in node.js, that mostly revolve around multiple processes. But like all of node.js, they are in the early stages of development. For example, you can manage multiple worker processes using fugue, or you can use the possibly familiar Web Workers API using node-worker.

×眷恋的温暖 2024-10-06 20:39:59

请参阅限制执行时间。这是可能的,但我不确定它有多大可能像 Java 那样简单。

See limiting execution time. It's possible but I'm not sure how likely it is to be as easy as say Java.

去了角落 2024-10-06 20:39:59

从 v0.6 开始,您可以使用集群设施

单独的节点进程之间的通信会产生一些开销,因此,v8 隔离的支持考虑了一段时间,但最终没有继续实施 由于改进不足与复杂性权衡。

(v8 隔离将允许使用线程而不是进程,从而实现更有效的通信。)

Since v0.6 you can use the cluster facility.

The communication between the separate node processes incurs some overhead, and because of this, the support of v8 isolates was considered for some time, but eventually it was not pursued due to inadequate improvement vs complexity tradeoff.

(The v8 isolates would enable the use of threads instead of processes, allowing for more efficient communication.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文