mirror of https://github.com/grpc/grpc-node.git
Added requested comments
This commit is contained in:
parent
478481f97f
commit
37ae0f7718
|
|
@ -31,6 +31,14 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script runs a QPS test. It sends requests for a specified length of time
|
||||||
|
* with a specified number pending at any one time. It then outputs the measured
|
||||||
|
* QPS. Usage:
|
||||||
|
* node qps_test.js [--concurrent=count] [--time=seconds]
|
||||||
|
* concurrent defaults to 100 and time defaults to 10
|
||||||
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
@ -40,18 +48,35 @@ var grpc = require('..');
|
||||||
var testProto = grpc.load(__dirname + '/../interop/test.proto').grpc.testing;
|
var testProto = grpc.load(__dirname + '/../interop/test.proto').grpc.testing;
|
||||||
var interop_server = require('../interop/interop_server.js');
|
var interop_server = require('../interop/interop_server.js');
|
||||||
|
|
||||||
function runTest(concurrent, seconds, callback) {
|
/**
|
||||||
|
* Runs the QPS test. Sends requests constantly for the given number of seconds,
|
||||||
|
* and keeps concurrent_calls requests pending at all times. When the test ends,
|
||||||
|
* the callback is called with the number of calls that completed within the
|
||||||
|
* time limit.
|
||||||
|
* @param {number} concurrent_calls The number of calls to have pending
|
||||||
|
* simultaneously
|
||||||
|
* @param {number} seconds The number of seconds to run the test for
|
||||||
|
* @param {function(Error, number)} callback Callback for test completion
|
||||||
|
*/
|
||||||
|
function runTest(concurrent_calls, seconds, callback) {
|
||||||
var testServer = interop_server.getServer(0, false);
|
var testServer = interop_server.getServer(0, false);
|
||||||
testServer.server.listen();
|
testServer.server.listen();
|
||||||
var client = new testProto.TestService('localhost:' + testServer.port);
|
var client = new testProto.TestService('localhost:' + testServer.port);
|
||||||
|
|
||||||
var warmup_num = 100;
|
var warmup_num = 100;
|
||||||
|
|
||||||
async.waterfall([
|
/**
|
||||||
|
* Warms up the client to avoid counting startup time in the test result
|
||||||
|
* @param {function(Error)} callback Called when warmup is complete
|
||||||
|
*/
|
||||||
function warmUp(callback) {
|
function warmUp(callback) {
|
||||||
var pending = warmup_num;
|
var pending = warmup_num;
|
||||||
function startCall() {
|
function startCall() {
|
||||||
client.emptyCall({}, function(err, resp) {
|
client.emptyCall({}, function(err, resp) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
pending--;
|
pending--;
|
||||||
if (pending === 0) {
|
if (pending === 0) {
|
||||||
callback(null);
|
callback(null);
|
||||||
|
|
@ -61,7 +86,15 @@ function runTest(concurrent, seconds, callback) {
|
||||||
for (var i = 0; i < warmup_num; i++) {
|
for (var i = 0; i < warmup_num; i++) {
|
||||||
startCall();
|
startCall();
|
||||||
}
|
}
|
||||||
}, function run(callback) {
|
}
|
||||||
|
/**
|
||||||
|
* Run the QPS test. Starts concurrent_calls requests, then starts a new
|
||||||
|
* request whenever one completes until time runs out.
|
||||||
|
* @param {function(Error, number)} callback Called when the test is complete.
|
||||||
|
* The second argument is the number of calls that finished within the
|
||||||
|
* time limit
|
||||||
|
*/
|
||||||
|
function run(callback) {
|
||||||
var running = 0;
|
var running = 0;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var start = process.hrtime();
|
var start = process.hrtime();
|
||||||
|
|
@ -76,11 +109,12 @@ function runTest(concurrent, seconds, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var i = 0; i < concurrent; i++) {
|
for (var i = 0; i < concurrent_calls; i++) {
|
||||||
running += 1;
|
running += 1;
|
||||||
client.emptyCall({}, responseCallback);
|
client.emptyCall({}, responseCallback);
|
||||||
}
|
}
|
||||||
}], function(err, count) {
|
}
|
||||||
|
async.waterfall([warmUp, run], function(err, count) {
|
||||||
testServer.server.shutdown();
|
testServer.server.shutdown();
|
||||||
callback(err, count);
|
callback(err, count);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue