Fix a sporadic warning in cluster-geo, and fix test to not overload the test-watcher.

This commit is contained in:
Adam Ierymenko 2015-11-10 13:09:58 -08:00
parent 2854f14966
commit 0e4a2c378f
3 changed files with 25 additions and 16 deletions

View File

@ -5,8 +5,14 @@
// //
// GeoIP cache TTL in ms // GeoIP cache TTL in ms
var CACHE_TTL = (60 * 60 * 24 * 60 * 1000); // 60 days var CACHE_TTL = (60 * 60 * 24 * 120 * 1000); // 120 days
// Globally increase event emitter maximum listeners
var EventEmitter = require('events');
EventEmitter.prototype._maxListeners = 1000;
process.setMaxListeners(1000);
// Load config
var config = require(__dirname + '/config.js'); var config = require(__dirname + '/config.js');
if (!config.maxmind) { if (!config.maxmind) {

View File

@ -97,7 +97,7 @@ function agentIdToIp(agentId)
}; };
var lastTestResult = null; var lastTestResult = null;
var allOtherAgents = []; var allOtherAgents = {};
function doTest() function doTest()
{ {
@ -114,16 +114,19 @@ function doTest()
if (body) { if (body) {
try { try {
var peers = JSON.parse(body); var peers = JSON.parse(body);
if (Array.isArray(peers)) if (Array.isArray(peers)) {
allOtherAgents = allOtherAgents.concat(peers); for(var xx=0;xx<peers.length;++xx)
allOtherAgents[peers[xx]] = true;
}
} catch (e) {} } catch (e) {}
} }
if (allOtherAgents.length > 1) { var agents = Object.keys(allOtherAgents);
if (agents.length > 1) {
var target = allOtherAgents[Math.floor(Math.random() * allOtherAgents.length)]; var target = agents[Math.floor(Math.random() * agents.length)];
while (target === thisAgentId) while (target === thisAgentId)
target = allOtherAgents[Math.floor(Math.random() * allOtherAgents.length)]; target = agents[Math.floor(Math.random() * agents.length)];
var testRequest = null; var testRequest = null;
var timeoutId = null; var timeoutId = null;

View File

@ -34,16 +34,16 @@ app.post('/:agentId',function(req,res) {
} catch (e) {} } catch (e) {}
} }
var thisUpdate = null; knownAgents[agentId] = true;
if (!(agentId in knownAgents)) { var thisUpdate = [];
thisUpdate = Object.keys(knownAgents); var agents = Object.keys(knownAgents);
for(var id in knownAgents) if (agents.length < 100)
knownAgents[id].push(agentId); thisUpdate = agents;
knownAgents[agentId] = []; else {
} else { for(var xx=0;xx<100;++xx)
thisUpdate = knownAgents[agentId]; thisUpdate.push(agents[Math.floor(Math.random() * agents.length)]);
knownAgents[agentId] = [];
} }
return res.status(200).send(JSON.stringify(thisUpdate)); return res.status(200).send(JSON.stringify(thisUpdate));
}); });