Skip to content

Commit 4a8ec12

Browse files
authored
Merge pull request #2523 from murgatroid99/benchmark_improvements
Fix some issues with the benchmark code
2 parents 867caad + 5759b70 commit 4a8ec12

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

test/any_grpc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function getImplementation(globalField) {
2525
const impl = global[globalField];
2626

2727
if (impl === 'js') {
28-
return require(`../packages/grpc-${impl}`);
28+
return require('../packages/grpc-js');
2929
} else if (impl === 'native') {
3030
return require('grpc');
3131
}

test/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"dependencies": {
1717
"express": "^4.16.3",
1818
"google-auth-library": "^6.1.0",
19-
"grpc": "^1.24.2",
2019
"lodash": "^4.17.4",
2120
"poisson-process": "^1.0.0"
21+
},
22+
"optionalDependencies": {
23+
"grpc": "^1.24.2"
2224
}
2325
}

test/performance/benchmark_server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ util.inherits(BenchmarkServer, EventEmitter);
154154
* Start the benchmark server.
155155
*/
156156
BenchmarkServer.prototype.start = function() {
157-
this.server.bindAsync(this.host + ':' + this.port, this.creds, (err) => {
157+
this.server.bindAsync(this.host + ':' + this.port, this.creds, (err, port) => {
158158
assert.ifError(err);
159+
this.port = port;
159160
this.server.start();
160161
this.last_wall_time = process.hrtime();
161162
this.last_usage = process.cpuUsage();

test/performance/driver.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const grpc = require('../any_grpc').server;
2+
const protoLoader = require('../../packages/proto-loader');
3+
const protoPackage = protoLoader.loadSync(
4+
'src/proto/grpc/testing/worker_service.proto',
5+
{keepCase: true,
6+
defaults: true,
7+
enums: String,
8+
oneofs: true,
9+
includeDirs: [__dirname + '/../proto/']});
10+
const serviceProto = grpc.loadPackageDefinition(protoPackage).grpc.testing;
11+
12+
function main() {
13+
const parseArgs = require('minimist');
14+
const argv = parseArgs(process.argv, {
15+
string: ['client_worker_port', 'server_worker_port']
16+
});
17+
const clientWorker = new serviceProto.WorkerService(`localhost:${argv.client_worker_port}`, grpc.credentials.createInsecure());
18+
const serverWorker = new serviceProto.WorkerService(`localhost:${argv.server_worker_port}`, grpc.credentials.createInsecure());
19+
const serverWorkerStream = serverWorker.runServer();
20+
const clientWorkerStream = clientWorker.runClient();
21+
let firstServerResponseReceived = false;
22+
let markCount = 0;
23+
serverWorkerStream.on('data', (response) => {
24+
console.log('Server stats:', response.stats);
25+
if (!firstServerResponseReceived) {
26+
firstServerResponseReceived = true;
27+
clientWorkerStream.write({
28+
setup: {
29+
server_targets: [`localhost:${response.port}`],
30+
client_channels: 1,
31+
outstanding_rpcs_per_channel: 1,
32+
histogram_params: {
33+
resolution: 0.01,
34+
max_possible:60000000000
35+
},
36+
payload_config: {
37+
bytebuf_params: {
38+
req_size: 10,
39+
resp_size: 10
40+
}
41+
},
42+
load_params: {
43+
closed_loop: {}
44+
}
45+
}
46+
});
47+
clientWorkerStream.on('status', (status) => {
48+
console.log('Received client worker status ' + JSON.stringify(status));
49+
serverWorkerStream.end();
50+
});
51+
const markInterval = setInterval(() => {
52+
if (markCount >= 5) {
53+
clientWorkerStream.end();
54+
clearInterval(markInterval);
55+
} else {
56+
clientWorkerStream.write({
57+
mark: {}
58+
});
59+
serverWorkerStream.write({
60+
mark: {}
61+
});
62+
}
63+
markCount += 1;
64+
}, 1000);
65+
}
66+
});
67+
clientWorkerStream.on('data', (response) => {
68+
console.log('Client stats:', response.stats);
69+
});
70+
serverWorkerStream.write({
71+
setup: {
72+
port: 0
73+
}
74+
});
75+
serverWorkerStream.on('status', (status) => {
76+
console.log('Received server worker status ' + JSON.stringify(status));
77+
});
78+
}
79+
80+
if (require.main === module) {
81+
main();
82+
}

test/performance/worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ function runServer(port, benchmark_impl, callback) {
3939
server.addService(serviceProto.WorkerService.service,
4040
new WorkerServiceImpl(benchmark_impl, server));
4141
var address = '0.0.0.0:' + port;
42-
server.bindAsync(address, server_creds, (err) => {
42+
server.bindAsync(address, server_creds, (err, port) => {
4343
if (err) {
4444
return callback(err);
4545
}
4646

4747
server.start();
48-
console.log('running QPS worker on %s', address);
48+
console.log('running QPS worker on 0.0.0.0:%s', port);
4949
callback(null, server);
5050
});
5151
}

0 commit comments

Comments
 (0)