Okay, so I have a bot hosting thing I do. It's pretty much the only thing I have right now that's keeping me sane. It's an IRC type bot for a music/chat website, and it does a lot of things. But the problem is keeping them online. I used to use a sh file that would start all the bots individually with forever.
cd dir/bots
forever start bot1.js
forever start bot2.js
...
etc, etc. And that worked. But the bots themselves take around 30mb of RAM, while the forever process ALSO takes around 30mb of RAM. So with as many bots as I was running, I was near maxed out on RAM, and that wasn't good, because if I had to get another server, things would get infinitely more complicated for me, and if I'm being honest, I'm not very good at this.
So I did some research, and figured I'd just use child.fork()
and use one bot.js to spawn the rest of the bots. And it works beautifully, and cut my ram useage down to less than half of what it was. But now it's a pain keeping the bots online.
var child = require("child_process");
var running = {};
var bots = ["bot1","bot2","bot3"];
for (var i=0;i<bots.length;i++) {
running[bots[i]] = child.fork("bots/"+bots[i]+".js");
};
My question is - is this the most efficient way to run this setup? Because they are constantly crashing, and if I want to be considered reliable by any means, they need to be pretty self sufficient, and just shutting off in the wee hours of the night whilst I'm sleeping.
Right now I am using node-scheduler to create a fake cron job that sends a message to the bots (not a node message, because that would return as long as the js file is running, not if the bot is connected to the service) from the service, and have the bot return a command. And it sets a command, so that if it doesn't get a response from the bot in 15 seconds, it reboots it. But it doesn't seem to be working all the time. And I'm at a loss.
Any help would be appreciated, and I'll provide more details if I can.