Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long-running computations in 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?

like image 317
nornagon Avatar asked Sep 28 '10 01:09

nornagon


People also ask

Is NodeJS good for heavy computation?

Node. js is not the best platform to handle heavy computation. No, you definitely don't want to build a Fibonacci computation server in Node. js.

What is runtime in NodeJS?

The Node. js runtime is the software stack responsible for installing your web service's code and its dependencies and running your service. The Node.js runtime for App Engine in the standard environment is declared in the app.yaml file: Node.js 16.

Is NodeJS good for large applications?

NodeJS is a cross-platform run time environment built on Chrome's V8 engine. It has become a popular platform for web application development for how it simplifies the development process for small to large web apps.


1 Answers

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.

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.

like image 184
Andrew Pendleton Avatar answered Oct 01 '22 02:10

Andrew Pendleton