Skip to content

Commit

Permalink
test: add test-benchmark-http2
Browse files Browse the repository at this point in the history
PR-URL: #23863
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed Oct 29, 2018
1 parent 2f1c356 commit 2812759
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
16 changes: 9 additions & 7 deletions benchmark/_http-benchmarkers.js
Expand Up @@ -82,10 +82,12 @@ class WrkBenchmarker {
* works
*/
class TestDoubleBenchmarker {
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
@@ -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
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
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
@@ -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
});

0 comments on commit 2812759

Please sign in to comment.