From 7d1ad2df4c392a0babf00e7c3dd5fa8c18e542ec Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Tue, 13 Aug 2013 23:32:30 +0100 Subject: [PATCH] Batch clients into sets of 100 for reconfig command --- server/client.js | 3 +++ server/kiwi.js | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/client.js b/server/client.js index 2634cbb..3caef07 100755 --- a/server/client.js +++ b/server/client.js @@ -45,6 +45,8 @@ var Client = function (websocket) { websocket.on('error', function () { websocketError.apply(that, arguments); }); + + this.disposed = false; }; util.inherits(Client, events.EventEmitter); @@ -67,6 +69,7 @@ Client.prototype.sendKiwiCommand = function (command, data, callback) { }; Client.prototype.dispose = function () { + this.disposed = true; this.emit('dispose'); this.removeAllListeners(); }; diff --git a/server/kiwi.js b/server/kiwi.js index 26d5b9c..12e5106 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -147,9 +147,28 @@ global.servers = { config.on('loaded', function () { + var clients = []; for (var client in global.clients.clients) { - global.clients.clients[client].sendKiwiCommand('reconfig'); + clients.push(global.clients.clients[client]); } + var sendReconfigCommand = function (list) { + var cutoff; + if (list.length >= 100) { + setTimeout(function () { + sendReconfigCommand(list.slice(100)); + }, 200); + cutoff = 100; + } else { + cutoff = list.length; + } + list.slice(0, cutoff).forEach(function (client) { + if (!client.disposed) { + client.sendKiwiCommand('reconfig'); + } + }); + }; + + sendReconfigCommand(clients); }); -- 2.25.1