Batch clients into sets of 100 for reconfig command
authorJack Allnutt <jack@allnutt.eu>
Tue, 13 Aug 2013 22:32:30 +0000 (23:32 +0100)
committerJack Allnutt <jack@allnutt.eu>
Tue, 13 Aug 2013 22:32:30 +0000 (23:32 +0100)
server/client.js
server/kiwi.js

index 2634cbb81c7c2e5dcfe7a7a7d6a73ee23ea295fd..3caef07bc95ce42bc695cd56661fb5588992d571 100755 (executable)
@@ -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();
 };
index 26d5b9c14b06d7c8c43b2636ac61f97f87a91bd6..12e5106098054fd85d08deed81e233b19db0ef02 100755 (executable)
@@ -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);
 });