I was working on a Meteor project which is connected to a mongoDB hosted on MongoLab. Since it is a sandbox plan, the oplog of the mongoDB instance is not available and in that case the Meteor will keep polling the mongoDB in around every 10 seconds. This causes a very high consumption on CPU and network bandwidth.
If you are running, Meteor 0.7.0 or above and your mongoDB has oplog enabled. You won’t experienced the problem.
Since the oplog is not available so the only workaround which i could think of is to unsubscribe the dataset. Here is a main.js which is executed when the app is loaded and when the user is idle for than 3 mins. Stop the subscription and that will stop polling the mongoDB.
var articleSubscription; // Subscribe the articles on mongoDB articleSubscription = Meteor.subscribe("articles", function () { console.log("Articles are ready"); }); Meteor.startup(function () { // Set timer to check if user is idle var idleTimer; $(this).mousemove(function(e){ // clear prior timeout, if any window.clearTimeout(idleTimer); // create new timeout (3 mins) idleTimer = window.setTimeout(isIdle, 180000); }); function isIdle() { articleSubscription.stop(); } });
Display a msg and ask the user to refresh if he wants to resume those stopped features.
Done =)
Reference: