From 2812759f9352e2d180aeea8c1999dd2c6ab36371 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 24 Oct 2018 19:23:25 -0700 Subject: [PATCH] test: add test-benchmark-http2 PR-URL: https://github.com/nodejs/node/pull/23863 Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- benchmark/_http-benchmarkers.js | 16 ++++++++------- benchmark/_test-double-benchmarker.js | 22 ++++++++++++++++---- benchmark/http2/headers.js | 3 +-- test/sequential/test-benchmark-http.js | 2 +- test/sequential/test-benchmark-http2.js | 27 +++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 test/sequential/test-benchmark-http2.js diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index 9079dff3ff83cc..baa50f72cde906 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -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() ]; diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index e2a0eb13126ed5..b9379b907ffa07 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -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(); diff --git a/benchmark/http2/headers.js b/benchmark/http2/headers.js index beb1d31b71338f..e2fad2ea02a0ee 100644 --- a/benchmark/http2/headers.js +++ b/benchmark/http2/headers.js @@ -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 }) { diff --git a/test/sequential/test-benchmark-http.js b/test/sequential/test-benchmark-http.js index 22efce51909481..7255e655c094e6 100644 --- a/test/sequential/test-benchmark-http.js +++ b/test/sequential/test-benchmark-http.js @@ -13,7 +13,7 @@ const runBenchmark = require('../common/benchmark'); runBenchmark('http', [ - 'benchmarker=test-double', + 'benchmarker=test-double-http', 'c=1', 'chunkedEnc=true', 'chunks=0', diff --git a/test/sequential/test-benchmark-http2.js b/test/sequential/test-benchmark-http2.js new file mode 100644 index 00000000000000..0abe490973b38d --- /dev/null +++ b/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 + });