11 ms·
You can use Node's cluster API[1] directly or use a wrapping module such as Recluster[2]. With these, node will spawn a few children that get replaced when they
by lost_my_pwd 12y ago
You can use Node's cluster API[1] directly or use a wrapping module such as Recluster[2]. With these, node will spawn a few children that get replaced when they die or time out (a little extra code is needed for the latter).
One can even do rolling upgrades with this for zero downtime releases.
If there is a known workload that will block for a while, one could 1) run the work in a child process, 2) consider using streams to process the data in chunks, or 3) break the work up by chaining smaller operations using "process.nextTick" to put the next operation at the end of the event loop (allows other pending operations to resume before continuing the slow/blocking work).
[1] http://nodejs.org/api/cluster.html http://nodejs.org/api/cluster.html
[2] https://www.npmjs.com/package/recluster https://www.npmjs.com/package/recluster