在node.js中长时间运行的计算 [英] Long-running computations in node.js

查看:122
本文介绍了在node.js中长时间运行的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用node.js编写游戏服务器,并且某些操作涉及服务器部分的大量计算.我不想在运行这些计算时停止接受连接-当node.js不支持线程时如何在后台运行它们?

I'm writing a game server in node.js, and some operations involve heavy computation on part of the server. I don't want to stop accepting connections while I run those computations -- how can I run them in the background when node.js doesn't support threads?

推荐答案

我个人不能为上述任何一项提供担保,但是如果您热衷于进行中的工作,则可以考虑一些节点模块页面上列出的针对节点的WebWorkers API的独立实现的说明:

I can't vouch for either of these, personally, but if you're hell-bent on doing the work in-process, there have been a couple of independent implementations of the WebWorkers API for node, as listed on the node modules page:

  • http://github.com/cramforce/node-worker
  • http://github.com/pgriess/node-webworker

乍一看,第二个看起来更成熟,而且它们都可以让您进行线程编程,但是它基本上是参与者模型,因此都通过消息传递来完成,并且您不能拥有共享的数据结构或任何东西.

At first glance, the second looks more mature, and these would both allow you to essentially do threaded programming, but it's basically actor-model, so it's all done with message passing, and you can't have shared data structures or anything.

此外,就其价值而言,node.js团队最终打算在本机上精确地实现此API,因此,即使这些工具不够完善,它们也可能是一个不错的权宜之计.

Also, for what it's worth, the node.js team intends to implement precisely this API natively, eventually, so these tools, even if they're not perfect, may be a decent stopgap.

这篇关于在node.js中长时间运行的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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