Created
February 1, 2017 22:00
-
-
Save StarpTech/a8032cb07ff17da691788bfda3df75af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nc1 = require('../lib/nats').connect(); | |
var nc2 = require('../lib/nats').connect(); | |
var os = require('os') | |
/////////////////////////////////////// | |
// Request Performance | |
/////////////////////////////////////// | |
var start; | |
var loop = 100000; | |
var hash = 1000; | |
var received = 0; | |
console.log('Request Performance Test'); | |
nc1.on('connect', function () { | |
var start = new Date(); | |
var counter = 0 | |
nc1.subscribe('request.test', function (msg, reply) { | |
nc1.publish(reply, JSON.stringify({ | |
pid: process.pid, | |
hostname: os.hostname(), | |
uptime: process.uptime(), | |
counter: counter++ | |
})); | |
}); | |
// Need to flush here since using separate connections. | |
nc1.flush(function () { | |
for (var i = 0; i < loop; i++) { | |
nc2.request('request.test', 'help', { | |
'max': 1 | |
}, function () { | |
received += 1; | |
if (received === loop) { | |
var stop = new Date(); | |
var rps = parseInt(loop / ((stop - start) / 1000)); | |
console.log('\n' + rps + ' request-responses/sec'); | |
var lat = parseInt(((stop - start) * 1000) / (loop * 2)); // Request=2, Reponse=2 RTs | |
console.log('Avg roundtrip latency: ' + lat + ' microseconds'); | |
process.exit(); | |
} else if (received % hash === 0) { | |
process.stdout.write('+'); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment