mirror of https://github.com/grpc/grpc-node.git
Fixed some bugs in node benchmark service
This commit is contained in:
parent
c98b20329e
commit
eb7b4a332c
|
|
@ -40,6 +40,8 @@
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var util = require('util');
|
||||||
|
var EventEmitter = require('events');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var PoissonProcess = require('poisson-process');
|
var PoissonProcess = require('poisson-process');
|
||||||
var Histogram = require('./histogram');
|
var Histogram = require('./histogram');
|
||||||
|
|
@ -101,8 +103,12 @@ function BenchmarkClient(server_targets, channels, histogram_params,
|
||||||
histogram_params.max_possible);
|
histogram_params.max_possible);
|
||||||
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
|
||||||
|
this.pending_calls = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
util.inherits(BenchmarkClient, EventEmitter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a closed-loop test. For each channel, start
|
* Start a closed-loop test. For each channel, start
|
||||||
* outstanding_rpcs_per_channel RPCs. Then, whenever an RPC finishes, start
|
* outstanding_rpcs_per_channel RPCs. Then, whenever an RPC finishes, start
|
||||||
|
|
@ -134,28 +140,37 @@ BenchmarkClient.prototype.startClosedLoop = function(
|
||||||
if (rpc_type == 'UNARY') {
|
if (rpc_type == 'UNARY') {
|
||||||
makeCall = function(client) {
|
makeCall = function(client) {
|
||||||
if (self.running) {
|
if (self.running) {
|
||||||
|
self.pending_calls++;
|
||||||
var start_time = process.hrtime();
|
var start_time = process.hrtime();
|
||||||
client.unaryCall(argument, function(error, response) {
|
client.unaryCall(argument, function(error, response) {
|
||||||
// Ignoring error for now
|
// Ignoring error for now
|
||||||
var time_diff = process.hrtime(start_time);
|
var time_diff = process.hrtime(start_time);
|
||||||
self.histogram.add(time_diff);
|
self.histogram.add(time_diff);
|
||||||
makeCall(client);
|
makeCall(client);
|
||||||
|
self.pending_calls--;
|
||||||
|
if ((!self.running) && self.pending_calls == 0) {
|
||||||
|
self.emit('finished');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
makeCall = function(client) {
|
makeCall = function(client) {
|
||||||
if (self.running) {
|
if (self.running) {
|
||||||
|
self.pending_calls++;
|
||||||
var start_time = process.hrtime();
|
var start_time = process.hrtime();
|
||||||
var call = client.streamingCall();
|
var call = client.streamingCall();
|
||||||
call.write(argument);
|
call.write(argument);
|
||||||
call.on('data', function() {
|
call.on('data', function() {
|
||||||
});
|
});
|
||||||
call.on('end', function() {
|
call.on('end', function() {
|
||||||
// Ignoring error for now
|
|
||||||
var time_diff = process.hrtime(start_time);
|
var time_diff = process.hrtime(start_time);
|
||||||
self.histogram.add(time_diff);
|
self.histogram.add(time_diff);
|
||||||
makeCall(client);
|
makeCall(client);
|
||||||
|
self.pending_calls--;
|
||||||
|
if ((!self.running) && self.pending_calls == 0) {
|
||||||
|
self.emit('finished');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -200,11 +215,16 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
if (rpc_type == 'UNARY') {
|
if (rpc_type == 'UNARY') {
|
||||||
makeCall = function(client, poisson) {
|
makeCall = function(client, poisson) {
|
||||||
if (self.running) {
|
if (self.running) {
|
||||||
|
self.pending_calls++;
|
||||||
var start_time = process.hrtime();
|
var start_time = process.hrtime();
|
||||||
client.unaryCall(argument, function(error, response) {
|
client.unaryCall(argument, function(error, response) {
|
||||||
// Ignoring error for now
|
// Ignoring error for now
|
||||||
var time_diff = process.hrtime(start_time);
|
var time_diff = process.hrtime(start_time);
|
||||||
self.histogram.add(time_diff);
|
self.histogram.add(time_diff);
|
||||||
|
self.pending_calls--;
|
||||||
|
if ((!self.running) && self.pending_calls == 0) {
|
||||||
|
self.emit('finished');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
poisson.stop();
|
poisson.stop();
|
||||||
|
|
@ -213,15 +233,19 @@ BenchmarkClient.prototype.startPoisson = function(
|
||||||
} else {
|
} else {
|
||||||
makeCall = function(client, poisson) {
|
makeCall = function(client, poisson) {
|
||||||
if (self.running) {
|
if (self.running) {
|
||||||
|
self.pending_calls++;
|
||||||
var start_time = process.hrtime();
|
var start_time = process.hrtime();
|
||||||
var call = client.streamingCall();
|
var call = client.streamingCall();
|
||||||
call.write(argument);
|
call.write(argument);
|
||||||
call.on('data', function() {
|
call.on('data', function() {
|
||||||
});
|
});
|
||||||
call.on('end', function() {
|
call.on('end', function() {
|
||||||
// Ignoring error for now
|
|
||||||
var time_diff = process.hrtime(start_time);
|
var time_diff = process.hrtime(start_time);
|
||||||
self.histogram.add(time_diff);
|
self.histogram.add(time_diff);
|
||||||
|
self.pending_calls--;
|
||||||
|
if ((!self.running) && self.pending_calls == 0) {
|
||||||
|
self.emit('finished');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
poisson.stop();
|
poisson.stop();
|
||||||
|
|
@ -279,9 +303,7 @@ BenchmarkClient.prototype.mark = function(reset) {
|
||||||
*/
|
*/
|
||||||
BenchmarkClient.prototype.stop = function(callback) {
|
BenchmarkClient.prototype.stop = function(callback) {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
/* TODO(murgatroid99): Figure out how to check that the clients have finished
|
self.on('finished', callback);
|
||||||
* before calling this */
|
|
||||||
callback();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = BenchmarkClient;
|
module.exports = BenchmarkClient;
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ function BenchmarkServer(host, port, tls) {
|
||||||
server_creds = grpc.ServerCredentials.createInsecure();
|
server_creds = grpc.ServerCredentials.createInsecure();
|
||||||
}
|
}
|
||||||
|
|
||||||
var server = new Server();
|
var server = new grpc.Server();
|
||||||
this.port = server.bind(host + ':' + port, server_creds);
|
this.port = server.bind(host + ':' + port, server_creds);
|
||||||
server.addProtoService(serviceProto.BenchmarkService.service, {
|
server.addProtoService(serviceProto.BenchmarkService.service, {
|
||||||
unaryCall: unaryCall,
|
unaryCall: unaryCall,
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@
|
||||||
* pared down to the statistics needed for client stats in
|
* pared down to the statistics needed for client stats in
|
||||||
* test/proto/benchmarks/stats.proto.
|
* test/proto/benchmarks/stats.proto.
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {number} resolution The histogram's bucket resolution
|
* @param {number} resolution The histogram's bucket resolution. Must be positive
|
||||||
* @param {number} max_possible The maximum allowed value
|
* @param {number} max_possible The maximum allowed value. Must be greater than 1
|
||||||
*/
|
*/
|
||||||
function Histogram(resolution, max_possible) {
|
function Histogram(resolution, max_possible) {
|
||||||
this.resolution = resolution;
|
this.resolution = resolution;
|
||||||
|
|
|
||||||
|
|
@ -41,20 +41,23 @@ var serviceProto = grpc.load({
|
||||||
file: 'test/proto/benchmarks/services.proto'}).grpc.testing;
|
file: 'test/proto/benchmarks/services.proto'}).grpc.testing;
|
||||||
|
|
||||||
function runServer(port) {
|
function runServer(port) {
|
||||||
var server_creds;
|
var server_creds = grpc.ServerCredentials.createInsecure();
|
||||||
// Need to actually populate server_creds
|
|
||||||
var server = new grpc.Server();
|
var server = new grpc.Server();
|
||||||
server.addProtoService(serviceProto.WorkerService.service,
|
server.addProtoService(serviceProto.WorkerService.service,
|
||||||
worker_service_impl);
|
worker_service_impl);
|
||||||
server.bind('0.0.0.0:' + port, server_creds);
|
var address = '0.0.0.0:' + port;
|
||||||
|
server.bind(address, server_creds);
|
||||||
server.start();
|
server.start();
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
Error.stackTraceLimit = Infinity;
|
||||||
var parseArgs = require('minimist');
|
var parseArgs = require('minimist');
|
||||||
var argv = parseArgs(process.argv, {
|
var argv = parseArgs(process.argv, {
|
||||||
string: ['driver_port']
|
string: ['driver_port']
|
||||||
});
|
});
|
||||||
runServer(argv.driver_port);
|
runServer(argv.driver_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.runServer = runServer;
|
||||||
|
|
|
||||||
|
|
@ -39,18 +39,20 @@ var BenchmarkServer = require('./benchmark_server');
|
||||||
exports.runClient = function runClient(call) {
|
exports.runClient = function runClient(call) {
|
||||||
var client;
|
var client;
|
||||||
call.on('data', function(request) {
|
call.on('data', function(request) {
|
||||||
|
var stats;
|
||||||
switch (request.argtype) {
|
switch (request.argtype) {
|
||||||
case 'setup':
|
case 'setup':
|
||||||
var setup = request.setup;
|
var setup = request.setup;
|
||||||
client = new BenchmarkClient(setup.server_targets,
|
client = new BenchmarkClient(setup.server_targets,
|
||||||
setup.client_channels,
|
setup.client_channels,
|
||||||
setup.security_params,
|
setup.histogram_params,
|
||||||
setup.histogram_params);
|
setup.security_params);
|
||||||
switch (setup.load_params.load) {
|
switch (setup.load_params.load) {
|
||||||
case 'closed_loop':
|
case 'closed_loop':
|
||||||
client.startClosedLoop(setup.outstanding_rpcs_per_channel,
|
client.startClosedLoop(setup.outstanding_rpcs_per_channel,
|
||||||
setup.rpc_type, setup.payload_config.req_size,
|
setup.rpc_type,
|
||||||
setup.payload_config.resp_size);
|
setup.payload_config.simple_params.req_size,
|
||||||
|
setup.payload_config.simple_params.resp_size);
|
||||||
break;
|
break;
|
||||||
case 'poisson':
|
case 'poisson':
|
||||||
client.startPoisson(setup.outstanding_rpcs_per_channel,
|
client.startPoisson(setup.outstanding_rpcs_per_channel,
|
||||||
|
|
@ -62,9 +64,15 @@ exports.runClient = function runClient(call) {
|
||||||
call.emit('error', new Error('Unsupported LoadParams type' +
|
call.emit('error', new Error('Unsupported LoadParams type' +
|
||||||
setup.load_params.load));
|
setup.load_params.load));
|
||||||
}
|
}
|
||||||
|
stats = client.mark();
|
||||||
|
console.log(stats);
|
||||||
|
call.write({
|
||||||
|
stats: stats
|
||||||
|
});
|
||||||
|
break;
|
||||||
case 'mark':
|
case 'mark':
|
||||||
if (client) {
|
if (client) {
|
||||||
var stats = client.mark(request.mark.reset);
|
stats = client.mark(request.mark.reset);
|
||||||
call.write({
|
call.write({
|
||||||
stats: stats
|
stats: stats
|
||||||
});
|
});
|
||||||
|
|
@ -76,24 +84,30 @@ exports.runClient = function runClient(call) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
call.on('end', function() {
|
call.on('end', function() {
|
||||||
// TODO(murgatroid99): Ensure client is shutdown before calling call.end
|
client.stop(function() {
|
||||||
client.stop();
|
|
||||||
call.end();
|
call.end();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.runServer = function runServer(call) {
|
exports.runServer = function runServer(call) {
|
||||||
var server;
|
var server;
|
||||||
call.on('data', function(request) {
|
call.on('data', function(request) {
|
||||||
|
var stats;
|
||||||
switch (request.argtype) {
|
switch (request.argtype) {
|
||||||
case 'setup':
|
case 'setup':
|
||||||
server = new BenchmarkServer(request.setup.host, request.setup.port,
|
server = new BenchmarkServer(request.setup.host, request.setup.port,
|
||||||
request.setup.security_params);
|
request.setup.security_params);
|
||||||
server.start();
|
server.start();
|
||||||
|
stats = server.mark();
|
||||||
|
call.write({
|
||||||
|
stats: stats,
|
||||||
|
port: server.getPort()
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'mark':
|
case 'mark':
|
||||||
if (server) {
|
if (server) {
|
||||||
var stats = server.mark(request.mark.reset);
|
stats = server.mark(request.mark.reset);
|
||||||
call.write({
|
call.write({
|
||||||
stats: stats,
|
stats: stats,
|
||||||
port: server.getPort()
|
port: server.getPort()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue