test: add test-benchmark-http2

PR-URL: https://github.com/nodejs/node/pull/23863
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rich Trott 2018-10-24 19:23:25 -07:00 committed by Michaël Zasso
parent 45a20a8d78
commit ed10a91e83
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
5 changed files with 56 additions and 14 deletions

View File

@ -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) {
@ -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;
}
@ -167,7 +168,8 @@ class H2LoadBenchmarker {
const http_benchmarkers = [
new WrkBenchmarker(),
new AutocannonBenchmarker(),
new TestDoubleBenchmarker(),
new TestDoubleBenchmarker('http'),
new TestDoubleBenchmarker('http2'),
new H2LoadBenchmarker()
];

View File

@ -1,6 +1,11 @@
'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;
@ -8,8 +13,8 @@ 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++;
@ -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();

View File

@ -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 }) {

View File

@ -13,7 +13,7 @@ const runBenchmark = require('../common/benchmark');
runBenchmark('http',
[
'benchmarker=test-double',
'benchmarker=test-double-http',
'c=1',
'chunkedEnc=true',
'chunks=0',

View File

@ -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
});