Is the node thread the wrong place for a simulation loop?

Let's say there was a weather simulator generating/calculating made up weather, and every 0.5 seconds a setInterval fires off and runs a bunch of calculations to get readings and process data to be human readable.

Then it would fire off relevant data to logged in parties via socket, perhaps only when the data actually changes.

So would it be better to run the weather simulation/generator in a child process by itself and keep the I/O in node's single thread?

Or, would that create locking requirements?

I think the principle that should guide you is separation of concerns. Your node.js server is a communications conduit. Your weather simulator is simply that. Changes made to one of those is very unlikely to involve the other. This is also a more scalable choice, if later your weather simulator becomes heavier, or you start getting more users than you had expected.

If the web clients could, I'm sure they would want to subscribe directly to the weather events feed, but don't let that fool you into thinking that you should muddle the websockets in with the simulator.

If the calculations are intense, I'd highly recommend that you run them as a child process and keep the node.js event loop responsive. If you listen to the childs stdout for the events data and done, you can send out the data as soon as it is available.

Make sure you use the async read and writes so that you don't start blocking things and you won't have to worry about locks.