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:
Родитель
9fb91fe1d6
Коммит
98d1110721
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -25,4 +25,7 @@ runBenchmark('http',
|
|||
'res=normal',
|
||||
'type=asc'
|
||||
],
|
||||
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
|
||||
{
|
||||
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
|
||||
duration: 0
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче