开发者

rebooting node.js cluster workers

I have a node app I use cluster to run on multiple cores.

I'm running into an issue where when my app th开发者_JAVA技巧rows an exception, the worker dies and doesn't restart. That makes sense, but I'm wondering if there is a better way to handle restarting these workers instead of having to monitor it or try/catch or listen for every error.

I've used forever before, and it seems like something like this would work well for cluster.

Is there a way to reboot them, or add "pokemon" exception handling at a top layer in express to make sure my workers won't die if there's an unexpected exception?


There are many 3rd party tools that can help with this. Monit (http://mmonit.com/monit/) is quite popular in the Node community. Another option, of many, is supervise (http://cr.yp.to/daemontools.html).


fork the new worker when death event occurs

cluster.on("death", function(worker){
    console.log("worker " + worker.pid + " died");
    var newWorker = cluster.fork(); 
    console.log("worker " + newWorker.id + " live");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜