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
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');
if (!config.maxmind) {

View File

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

View File

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