Skip to content

Commit 2efa7d1

Browse files
joyeecheungevanlucas
authored andcommitted
benchmark: implement duration in http test double
PR-URL: #18380 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent b5ec6ea commit 2efa7d1

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

benchmark/_http-benchmarkers.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ class TestDoubleBenchmarker {
8989
}
9090

9191
create(options) {
92+
const env = Object.assign({
93+
duration: options.duration,
94+
test_url: `http://127.0.0.1:${options.port}${options.path}`,
95+
}, process.env);
96+
9297
const child = child_process.fork(this.executable, {
9398
silent: true,
94-
env: Object.assign({}, process.env, {
95-
test_url: `http://127.0.0.1:${options.port}${options.path}`
96-
})
99+
env
97100
});
98101
return child;
99102
}

benchmark/_test-double-benchmarker.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
const http = require('http');
44

5-
http.get(process.env.test_url, function() {
6-
console.log(JSON.stringify({ throughput: 1 }));
7-
});
5+
const duration = process.env.duration || 0;
6+
const url = process.env.test_url;
7+
8+
const start = process.hrtime();
9+
let throughput = 0;
10+
11+
function request(res) {
12+
res.on('data', () => {});
13+
res.on('error', () => {});
14+
res.on('end', () => {
15+
throughput++;
16+
const diff = process.hrtime(start);
17+
if (duration > 0 && diff[0] < duration) {
18+
run();
19+
} else {
20+
console.log(JSON.stringify({ throughput }));
21+
}
22+
});
23+
}
24+
25+
function run() {
26+
http.get(url, request);
27+
}
28+
29+
run();

test/sequential/test-benchmark-http.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ runBenchmark('http',
2525
'res=normal',
2626
'type=asc'
2727
],
28-
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
28+
{
29+
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
30+
duration: 0
31+
});

0 commit comments

Comments
 (0)