bgtask: run channel saves serially to prevent thrashing

This commit is contained in:
calzoneman 2015-10-09 23:16:21 -07:00
parent 7d35df4f5a
commit b4b442c897
2 changed files with 5 additions and 5 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.11.1", "version": "3.11.2",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -8,6 +8,7 @@
var Logger = require("./logger"); var Logger = require("./logger");
var Config = require("./config"); var Config = require("./config");
var db = require("./database"); var db = require("./database");
var Promise = require("bluebird");
var init = null; var init = null;
@ -61,14 +62,13 @@ function initChannelDumper(Server) {
var CHANNEL_SAVE_INTERVAL = parseInt(Config.get("channel-save-interval")) var CHANNEL_SAVE_INTERVAL = parseInt(Config.get("channel-save-interval"))
* 60000; * 60000;
setInterval(function () { setInterval(function () {
for (var i = 0; i < Server.channels.length; i++) { Promise.reduce(Server.channels, (_, chan) => {
var chan = Server.channels[i];
if (!chan.dead && chan.users && chan.users.length > 0) { if (!chan.dead && chan.users && chan.users.length > 0) {
chan.saveState().catch(err => { return chan.saveState().catch(err => {
Logger.errlog.log(`Failed to save /r/${chan.name}: ${err.stack}`); Logger.errlog.log(`Failed to save /r/${chan.name}: ${err.stack}`);
}); });
} }
} }, 0);
}, CHANNEL_SAVE_INTERVAL); }, CHANNEL_SAVE_INTERVAL);
} }