Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test-benchmark-http2 #23863

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions benchmark/_http-benchmarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ class WrkBenchmarker {
* works
*/
class TestDoubleBenchmarker {
Trott marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
this.name = 'test-double';
constructor(type) {
// `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
this.name = `test-double-${type}`;
this.executable = path.resolve(__dirname, '_test-double-benchmarker.js');
this.present = fs.existsSync(this.executable);
this.type = type;
}

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

const child = child_process.fork(this.executable, {
silent: true,
env
});
const child = child_process.fork(this.executable,
[this.type],
{ silent: true, env });
return child;
}

Expand Down Expand Up @@ -167,7 +168,8 @@ class H2LoadBenchmarker {
const http_benchmarkers = [
new WrkBenchmarker(),
new AutocannonBenchmarker(),
new TestDoubleBenchmarker(),
new TestDoubleBenchmarker('http'),
new TestDoubleBenchmarker('http2'),
new H2LoadBenchmarker()
];

Expand Down
22 changes: 18 additions & 4 deletions benchmark/_test-double-benchmarker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
'use strict';

const http = require('http');
const myModule = process.argv[2];
if (!['http', 'http2'].includes(myModule)) {
throw new Error(`Invalid module for benchmark test double: ${myModule}`);
}

const http = require(myModule);

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', () => {});
function request(res, client) {
res.resume();
res.on('error', () => {});
res.on('end', () => {
throughput++;
Expand All @@ -18,12 +23,21 @@ function request(res) {
run();
} else {
console.log(JSON.stringify({ throughput }));
if (client) {
client.destroy();
}
}
});
}

function run() {
http.get(url, request);
if (http.get) { // HTTP
http.get(url, request);
} else { // HTTP/2
const client = http.connect(url);
client.on('error', (e) => { throw e; });
request(client.request(), client);
}
}

run();
3 changes: 1 addition & 2 deletions benchmark/http2/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const PORT = common.PORT;

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

function main({ n, nheaders }) {
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-benchmark-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const runBenchmark = require('../common/benchmark');

runBenchmark('http',
[
'benchmarker=test-double',
'benchmarker=test-double-http',
'c=1',
'chunkedEnc=true',
'chunks=0',
Expand Down
27 changes: 27 additions & 0 deletions test/sequential/test-benchmark-http2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const common = require('../common');

if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP/2 benchmark test');

// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.

const runBenchmark = require('../common/benchmark');

runBenchmark('http2',
[
'benchmarker=test-double-http2',
'clients=1',
'length=65536',
'n=1',
'nheaders=0',
'requests=1',
'streams=1'
],
{
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
duration: 0
});