Skip to content

Commit ed10a91

Browse files
Trotttargos
authored andcommittedNov 1, 2018
test: add test-benchmark-http2
PR-URL: #23863 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 45a20a8 commit ed10a91

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed
 

‎benchmark/_http-benchmarkers.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ class WrkBenchmarker {
8282
* works
8383
*/
8484
class TestDoubleBenchmarker {
85-
constructor() {
86-
this.name = 'test-double';
85+
constructor(type) {
86+
// `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
87+
this.name = `test-double-${type}`;
8788
this.executable = path.resolve(__dirname, '_test-double-benchmarker.js');
8889
this.present = fs.existsSync(this.executable);
90+
this.type = type;
8991
}
9092

9193
create(options) {
@@ -94,10 +96,9 @@ class TestDoubleBenchmarker {
9496
test_url: `http://127.0.0.1:${options.port}${options.path}`,
9597
}, process.env);
9698

97-
const child = child_process.fork(this.executable, {
98-
silent: true,
99-
env
100-
});
99+
const child = child_process.fork(this.executable,
100+
[this.type],
101+
{ silent: true, env });
101102
return child;
102103
}
103104

@@ -167,7 +168,8 @@ class H2LoadBenchmarker {
167168
const http_benchmarkers = [
168169
new WrkBenchmarker(),
169170
new AutocannonBenchmarker(),
170-
new TestDoubleBenchmarker(),
171+
new TestDoubleBenchmarker('http'),
172+
new TestDoubleBenchmarker('http2'),
171173
new H2LoadBenchmarker()
172174
];
173175

‎benchmark/_test-double-benchmarker.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use strict';
22

3-
const http = require('http');
3+
const myModule = process.argv[2];
4+
if (!['http', 'http2'].includes(myModule)) {
5+
throw new Error(`Invalid module for benchmark test double: ${myModule}`);
6+
}
7+
8+
const http = require(myModule);
49

510
const duration = process.env.duration || 0;
611
const url = process.env.test_url;
712

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

11-
function request(res) {
12-
res.on('data', () => {});
16+
function request(res, client) {
17+
res.resume();
1318
res.on('error', () => {});
1419
res.on('end', () => {
1520
throughput++;
@@ -18,12 +23,21 @@ function request(res) {
1823
run();
1924
} else {
2025
console.log(JSON.stringify({ throughput }));
26+
if (client) {
27+
client.destroy();
28+
}
2129
}
2230
});
2331
}
2432

2533
function run() {
26-
http.get(url, request);
34+
if (http.get) { // HTTP
35+
http.get(url, request);
36+
} else { // HTTP/2
37+
const client = http.connect(url);
38+
client.on('error', (e) => { throw e; });
39+
request(client.request(), client);
40+
}
2741
}
2842

2943
run();

‎benchmark/http2/headers.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const PORT = common.PORT;
55

66
const bench = common.createBenchmark(main, {
77
n: [1e3],
8-
nheaders: [0, 10, 100, 1000],
9-
benchmarker: ['h2load']
8+
nheaders: [0, 10, 100, 1000]
109
}, { flags: ['--no-warnings'] });
1110

1211
function main({ n, nheaders }) {

‎test/sequential/test-benchmark-http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const runBenchmark = require('../common/benchmark');
1313

1414
runBenchmark('http',
1515
[
16-
'benchmarker=test-double',
16+
'benchmarker=test-double-http',
1717
'c=1',
1818
'chunkedEnc=true',
1919
'chunks=0',
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.enoughTestMem)
6+
common.skip('Insufficient memory for HTTP/2 benchmark test');
7+
8+
// Because the http benchmarks use hardcoded ports, this should be in sequential
9+
// rather than parallel to make sure it does not conflict with tests that choose
10+
// random available ports.
11+
12+
const runBenchmark = require('../common/benchmark');
13+
14+
runBenchmark('http2',
15+
[
16+
'benchmarker=test-double-http2',
17+
'clients=1',
18+
'length=65536',
19+
'n=1',
20+
'nheaders=0',
21+
'requests=1',
22+
'streams=1'
23+
],
24+
{
25+
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
26+
duration: 0
27+
});

0 commit comments

Comments
 (0)
Please sign in to comment.