mirror of https://github.com/grpc/grpc-node.git
Fixed up the Node benchmark implementation
This commit is contained in:
parent
eb7b4a332c
commit
e8145ee504
|
@ -61,6 +61,17 @@ function zeroBuffer(size) {
|
|||
return zeros;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a time difference, as returned by process.hrtime, to a number of
|
||||
* nanoseconds.
|
||||
* @param {Array.<number>} time_diff The time diff, represented as
|
||||
* [seconds, nanoseconds]
|
||||
* @return {number} The total number of nanoseconds
|
||||
*/
|
||||
function timeDiffToNanos(time_diff) {
|
||||
return time_diff[0] * 1e9 + time_diff[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* The BenchmarkClient class. Opens channels to servers and makes RPCs based on
|
||||
* parameters from the driver, and records statistics about those RPCs.
|
||||
|
@ -143,9 +154,13 @@ BenchmarkClient.prototype.startClosedLoop = function(
|
|||
self.pending_calls++;
|
||||
var start_time = process.hrtime();
|
||||
client.unaryCall(argument, function(error, response) {
|
||||
// Ignoring error for now
|
||||
if (error) {
|
||||
self.emit('error', new Error('Client error: ' + error.message));
|
||||
self.running = false;
|
||||
return;
|
||||
}
|
||||
var time_diff = process.hrtime(start_time);
|
||||
self.histogram.add(time_diff);
|
||||
self.histogram.add(timeDiffToNanos(time_diff));
|
||||
makeCall(client);
|
||||
self.pending_calls--;
|
||||
if ((!self.running) && self.pending_calls == 0) {
|
||||
|
@ -165,13 +180,17 @@ BenchmarkClient.prototype.startClosedLoop = function(
|
|||
});
|
||||
call.on('end', function() {
|
||||
var time_diff = process.hrtime(start_time);
|
||||
self.histogram.add(time_diff);
|
||||
self.histogram.add(timeDiffToNanos(time_diff));
|
||||
makeCall(client);
|
||||
self.pending_calls--;
|
||||
if ((!self.running) && self.pending_calls == 0) {
|
||||
self.emit('finished');
|
||||
}
|
||||
});
|
||||
call.on('error', function(error) {
|
||||
self.emit('error', new Error('Client error: ' + error.message));
|
||||
self.running = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -218,9 +237,13 @@ BenchmarkClient.prototype.startPoisson = function(
|
|||
self.pending_calls++;
|
||||
var start_time = process.hrtime();
|
||||
client.unaryCall(argument, function(error, response) {
|
||||
// Ignoring error for now
|
||||
if (error) {
|
||||
self.emit('error', new Error('Client error: ' + error.message));
|
||||
self.running = false;
|
||||
return;
|
||||
}
|
||||
var time_diff = process.hrtime(start_time);
|
||||
self.histogram.add(time_diff);
|
||||
self.histogram.add(timeDiffToNanos(time_diff));
|
||||
self.pending_calls--;
|
||||
if ((!self.running) && self.pending_calls == 0) {
|
||||
self.emit('finished');
|
||||
|
@ -241,12 +264,16 @@ BenchmarkClient.prototype.startPoisson = function(
|
|||
});
|
||||
call.on('end', function() {
|
||||
var time_diff = process.hrtime(start_time);
|
||||
self.histogram.add(time_diff);
|
||||
self.histogram.add(timeDiffToNanos(time_diff));
|
||||
self.pending_calls--;
|
||||
if ((!self.running) && self.pending_calls == 0) {
|
||||
self.emit('finished');
|
||||
}
|
||||
});
|
||||
call.on('error', function(error) {
|
||||
self.emit('error', new Error('Client error: ' + error.message));
|
||||
self.running = false;
|
||||
});
|
||||
} else {
|
||||
poisson.stop();
|
||||
}
|
||||
|
@ -303,7 +330,7 @@ BenchmarkClient.prototype.mark = function(reset) {
|
|||
*/
|
||||
BenchmarkClient.prototype.stop = function(callback) {
|
||||
this.running = false;
|
||||
self.on('finished', callback);
|
||||
this.on('finished', callback);
|
||||
};
|
||||
|
||||
module.exports = BenchmarkClient;
|
||||
|
|
|
@ -87,6 +87,8 @@ Histogram.prototype.bucketStart = function(index) {
|
|||
* @param {number} value The value to add
|
||||
*/
|
||||
Histogram.prototype.add = function(value) {
|
||||
// Ensure value is a number
|
||||
value = +value;
|
||||
this.sum += value;
|
||||
this.sum_of_squares += value * value;
|
||||
this.count++;
|
||||
|
|
|
@ -47,6 +47,9 @@ exports.runClient = function runClient(call) {
|
|||
setup.client_channels,
|
||||
setup.histogram_params,
|
||||
setup.security_params);
|
||||
client.on('error', function(error) {
|
||||
call.emit('error', error);
|
||||
});
|
||||
switch (setup.load_params.load) {
|
||||
case 'closed_loop':
|
||||
client.startClosedLoop(setup.outstanding_rpcs_per_channel,
|
||||
|
@ -65,7 +68,6 @@ exports.runClient = function runClient(call) {
|
|||
setup.load_params.load));
|
||||
}
|
||||
stats = client.mark();
|
||||
console.log(stats);
|
||||
call.write({
|
||||
stats: stats
|
||||
});
|
||||
|
@ -79,8 +81,9 @@ exports.runClient = function runClient(call) {
|
|||
} else {
|
||||
call.emit('error', new Error('Got Mark before ClientConfig'));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error('Nonexistent client argtype option');
|
||||
throw new Error('Nonexistent client argtype option: ' + request.argtype);
|
||||
}
|
||||
});
|
||||
call.on('end', function() {
|
||||
|
@ -110,10 +113,11 @@ exports.runServer = function runServer(call) {
|
|||
stats = server.mark(request.mark.reset);
|
||||
call.write({
|
||||
stats: stats,
|
||||
port: server.getPort()
|
||||
port: server.getPort(),
|
||||
cores: 1
|
||||
});
|
||||
} else {
|
||||
call.emit('error', new Error('Got Mark befor ServerConfig'));
|
||||
call.emit('error', new Error('Got Mark before ServerConfig'));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue