Skip to content

Commit

Permalink
benchmark: implement duration in http test double
Browse files Browse the repository at this point in the history
PR-URL: #18380
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
joyeecheung committed Jan 29, 2018
1 parent 9fb91fe commit 98d1110
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
9 changes: 6 additions & 3 deletions benchmark/_http-benchmarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ class TestDoubleBenchmarker {
}

create(options) {
const env = Object.assign({
duration: options.duration,
test_url: `http://127.0.0.1:${options.port}${options.path}`,
}, process.env);

const child = child_process.fork(this.executable, {
silent: true,
env: Object.assign({}, process.env, {
test_url: `http://127.0.0.1:${options.port}${options.path}`
})
env
});
return child;
}
Expand Down
28 changes: 25 additions & 3 deletions benchmark/_test-double-benchmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

const http = require('http');

http.get(process.env.test_url, function() {
console.log(JSON.stringify({ throughput: 1 }));
});
const duration = process.env.duration || 0;
const url = process.env.test_url;

const start = process.hrtime();
let throughput = 0;

function request(res) {
res.on('data', () => {});
res.on('error', () => {});
res.on('end', () => {
throughput++;
const diff = process.hrtime(start);
if (duration > 0 && diff[0] < duration) {
run();
} else {
console.log(JSON.stringify({ throughput }));
}
});
}

function run() {
http.get(url, request);
}

run();
5 changes: 4 additions & 1 deletion test/sequential/test-benchmark-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ runBenchmark('http',
'res=normal',
'type=asc'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
{
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
duration: 0
});

0 comments on commit 98d1110

Please sign in to comment.