benchmark: implement duration in http test double
PR-URL: https://github.com/nodejs/node/pull/18380 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
9fb91fe1d6
commit
98d1110721
@ -89,11 +89,14 @@ class TestDoubleBenchmarker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create(options) {
|
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, {
|
const child = child_process.fork(this.executable, {
|
||||||
silent: true,
|
silent: true,
|
||||||
env: Object.assign({}, process.env, {
|
env
|
||||||
test_url: `http://127.0.0.1:${options.port}${options.path}`
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,28 @@
|
|||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
http.get(process.env.test_url, function() {
|
const duration = process.env.duration || 0;
|
||||||
console.log(JSON.stringify({ throughput: 1 }));
|
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();
|
||||||
|
@ -25,4 +25,7 @@ runBenchmark('http',
|
|||||||
'res=normal',
|
'res=normal',
|
||||||
'type=asc'
|
'type=asc'
|
||||||
],
|
],
|
||||||
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
|
{
|
||||||
|
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
|
||||||
|
duration: 0
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user