summaryrefslogtreecommitdiff
path: root/benchmark/_http-benchmarkers.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2020-01-16 15:57:30 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2020-02-09 13:31:45 +0100
commitdac579516ca662e731ac502c15e75009a2b9a8c9 (patch)
tree6e43173eab5da0563a5fbf39f5aa3bc64d47cbec /benchmark/_http-benchmarkers.js
parentb70741ea438b4df01cca416949a22e9350b58258 (diff)
downloadnode-new-dac579516ca662e731ac502c15e75009a2b9a8c9.tar.gz
benchmark: add `test` and `all` options and improve errors
This adds a new `test` option. Using it automatically uses a single minimal option matrix to verify the benchmark works as expected. Using the new `all` option makes sure all test suites are run. On top of that the benchmarks will from now on report properly what category might have a typo, if any. The http duration was also refactored to use a option instead of relying on a configuration setting. The fixture folder is ignored as test suite from now on. PR-URL: https://github.com/nodejs/node/pull/31396 Fixes: https://github.com/nodejs/node/issues/31083 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'benchmark/_http-benchmarkers.js')
-rw-r--r--benchmark/_http-benchmarkers.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js
index 821dab2d55..b1b0038435 100644
--- a/benchmark/_http-benchmarkers.js
+++ b/benchmark/_http-benchmarkers.js
@@ -43,9 +43,8 @@ class AutocannonBenchmarker {
}
if (!result || !result.requests || !result.requests.average) {
return undefined;
- } else {
- return result.requests.average;
}
+ return result.requests.average;
}
}
@@ -77,9 +76,8 @@ class WrkBenchmarker {
const throughput = match && +match[1];
if (!isFinite(throughput)) {
return undefined;
- } else {
- return throughput;
}
+ return throughput;
}
}
@@ -89,7 +87,8 @@ class WrkBenchmarker {
*/
class TestDoubleBenchmarker {
constructor(type) {
- // `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'.
+ // `type` is the type of benchmarker. 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);
@@ -97,10 +96,11 @@ class TestDoubleBenchmarker {
}
create(options) {
- const env = Object.assign({
+ const env = {
duration: options.duration,
test_url: `http://127.0.0.1:${options.port}${options.path}`,
- }, process.env);
+ ...process.env
+ };
const child = child_process.fork(this.executable,
[this.type],
@@ -189,13 +189,14 @@ http_benchmarkers.forEach((benchmarker) => {
});
exports.run = function(options, callback) {
- options = Object.assign({
+ options = {
port: exports.PORT,
path: '/',
connections: 100,
duration: 5,
benchmarker: exports.default_http_benchmarker,
- }, options);
+ ...options
+ };
if (!options.benchmarker) {
callback(new Error('Could not locate required http benchmarker. See ' +
`${requirementsURL} for further instructions.`));
@@ -212,6 +213,7 @@ exports.run = function(options, callback) {
'is not installed'));
return;
}
+ process.env.duration = process.env.duration || options.duration || 5;
const benchmarker_start = process.hrtime();
@@ -220,7 +222,8 @@ exports.run = function(options, callback) {
child.stderr.pipe(process.stderr);
let stdout = '';
- child.stdout.on('data', (chunk) => stdout += chunk.toString());
+ child.stdout.setEncoding('utf8');
+ child.stdout.on('data', (chunk) => stdout += chunk);
child.once('close', (code) => {
const elapsed = process.hrtime(benchmarker_start);