Change channel dumping to a single interval rather than per-channel

This commit is contained in:
calzoneman 2013-10-14 16:39:41 -05:00
parent 9193423923
commit 2e77cb4499
6 changed files with 50 additions and 40 deletions

View File

@ -1,3 +1,8 @@
Mon Oct 14 16:37 2013 CDT
* lib/bgtask.js: Add an interval for dumping all loaded channels
* lib/channel.js: Remove per-channel dump interval
* lib/config.js: Add config key for channel save interval
Mon Oct 14 16:30 2013 CDT
* lib/server.js: Rate-limit socket.io connections
* lib/bgtask.js: Periodically clear out old rate limiters

View File

@ -67,6 +67,18 @@ function initIpThrottleCleanup(Server) {
}, 5 * 60 * 1000);
}
function initChannelDumper(Server) {
var CHANNEL_SAVE_INTERVAL = Server.cfg["channel-save-interval"] * 60000;
setInterval(function () {
for (var i = 0; i < Server.channels.length; i++) {
var chan = Server.channels[i];
if (!chan.dead && chan.users && chan.users.length > 0) {
chan.saveDump();
}
}
}, CHANNEL_SAVE_INTERVAL);
}
module.exports = function (Server) {
if (init === Server) {
Logger.errlog.log("WARNING: Attempted to re-init background tasks");
@ -77,4 +89,5 @@ module.exports = function (Server) {
initStats(Server);
initAliasCleanup(Server);
initIpThrottleCleanup(Server);
initChannelDumper(Server);
};

View File

@ -276,7 +276,6 @@ Channel.prototype.loadDump = function() {
self.js = data.js || "";
self.sendAll("channelCSSJS", {css: self.css, js: self.js});
self.initialized = true;
setTimeout(function() { incrementalDump(self); }, 300000);
}
catch(e) {
Logger.errlog.log("Channel dump load failed: ");
@ -312,14 +311,6 @@ Channel.prototype.saveDump = function() {
fs.writeFileSync(path.join(__dirname, "../chandump", this.name), text);
}
// Save channel dumps every 5 minutes, in case of crash
function incrementalDump(chan) {
if(!chan.dead && chan.users && chan.users.length > 0) {
chan.saveDump();
setTimeout(function() { incrementalDump(chan); }, 300000);
}
}
Channel.prototype.readLog = function (filterIp, callback) {
var maxLen = 100000; // Most recent 100KB
var file = this.logger.filename;

View File

@ -30,6 +30,7 @@ var defaults = {
"io-port" : 1337,
"ip-connection-limit" : 10,
"guest-login-delay" : 60,
"channel-save-interval" : 5,
"trust-x-forward" : false,
"enable-mail" : false,
"mail-transport" : "SMTP",

View File

@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const VERSION = "2.4.3";
const VERSION = "2.4.4";
var singleton = null;
module.exports = {

View File

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