I'm performing a routine check on my DB every hour or so by doing
setInterval(function() {
myCheckFunction();
}, 3600000)
I'm thinking of something like :
setInterval(function() {
server.getConnections(function(err, count) {
if (count < X) {
myCheckFunction();
}
}, 3600000)
To check if there's isn't too much work being done right now.
Is it a good idea ? If so what value could X have ? If not, should I try differently or just do the test, non regarding of the current load ?
I don't expect millions of connections, this is just a proof of concept and my teacher asked me to take care of that kind of things.
Thanks !
Edit: Why do I want to avoid heavy load ? Because the routine check could take a couple of minutes and require a lot of work for the server. It has to contact at least 5 DNS server for each entry in the DB, request HTML code and hash it, then compare answers. The check for one entry can take up to 6 seconds due the the fact that the DNS servers can be Timeout and the DB is hosted separately from the project.
With this particular requirements, I would perform this check on server side instead.
var checkFunctionCaller = function () {
//call async function on server side and provide a callback function
//to be called as server returns an answer
server.myCheckFunction(function (result) {
// if server was able to run check - it return 'done' and everything is fine
if(result === "done") {
//do nothing
}
//otherwise, re-schedule a check in five minutes
setTimeout(checkFunctionCaller, 5 * 60 * 1000);
});
}
setInterval(checkFunctionCaller, 3600000);