Fixed up the Node benchmark implementation

pull/4321/head
murgatroid99 9 years ago
parent 722f910382
commit 6acc5f7574
  1. 41
      src/node/performance/benchmark_client.js
  2. 2
      src/node/performance/histogram.js
  3. 12
      src/node/performance/worker_service_impl.js
  4. 9
      test/cpp/qps/single_run_localhost.sh

@ -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:

@ -34,17 +34,15 @@ set -ex
cd $(dirname $0)/../../..
killall qps_worker || true
config=opt
NUMCPUS=`python2.7 -c 'import multiprocessing; print multiprocessing.cpu_count()'`
make CONFIG=$config qps_worker qps_driver -j$NUMCPUS
make CONFIG=$config qps_driver -j$NUMCPUS
bins/$config/qps_worker -driver_port 10000 &
node src/node/performance/worker_server.js --driver_port=10000 &
PID1=$!
bins/$config/qps_worker -driver_port 10010 &
node src/node/performance/worker_server.js --driver_port=10010 &
PID2=$!
export QPS_WORKERS="localhost:10000,localhost:10010"
@ -53,4 +51,3 @@ bins/$config/qps_driver $*
kill -2 $PID1 $PID2
wait

Loading…
Cancel
Save