Skip to content

Instantly share code, notes, and snippets.

@tsujio
Last active August 29, 2015 14:03
Show Gist options
  • Save tsujio/c49497d4dff96870f5ba to your computer and use it in GitHub Desktop.
Save tsujio/c49497d4dff96870f5ba to your computer and use it in GitHub Desktop.
request throughput measurement of webrtc-chord
var config = {
peer: { // The object to pass to the Peer constructor.
options: {
host: 'localhost',
port: '9000',
key: 'peerjs'
}
},
debug: false,
numberOfEntriesInSuccessorList: 5,
connectionPoolSize: 999,
connectionOpenTimeout: 30000,
requestTimeout: 180000,
stabilizeTaskInterval: 30000,
fixFingerTaskInterval: 30000,
checkPredecessorTaskInterval: 30000
};
var chords = [];
var entries = 100;
var CLIENTS_NUM = 20;
var i = 0;
chords[0] = new Chord(config);
chords[0].create(function(myPeerId, error) {
if (error) {
console.log("Failed to create chord network:", error);
} else {
console.log("Creating network, peer ID: ", myPeerId);
console.log("Adding other members")
joinOthers(myPeerId);
}
});
var joinOthers = function (bootstrapId) {
setInterval(function () {
i++;
if(i < CLIENTS_NUM) {
var chord = new Chord(config);
chord.join(bootstrapId, function(myPeerId, error) {
if (error) {
console.log("Failed to join chord network:", error);
} else {
chords.push(chord);
console.log('Chords array now contains', chords.length, 'entries');
console.log("Joining network, peer ID: ", myPeerId);
if (_.size(chords) === CLIENTS_NUM) {
startMeasurement(10);
}
}
});
}
}, 2000);
};
var startMeasurement = function(requestNum) {
var processedNum = 0;
var start = new Date();
for (var i = 0; i < requestNum; i++) {
chords[0].retrieve(Math.random().toString(), function() {
processedNum++;
//console.log(processedNum + " requests processed.");
if (processedNum === requestNum) {
var elapsed = new Date() - start;
console.log("elapsed " + elapsed + " milliseconds to process " + requestNum + " requests.");
startMeasurement(requestNum + 50);
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment