Revert "benchmark: add test and all options and improve errors"

This reverts commit dac579516c.

Refs: https://github.com/nodejs/node/pull/31396
PR-URL: https://github.com/nodejs/node/pull/31722
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Anna Henningsen
2020-02-10 20:03:46 +01:00
parent aa0a01bd36
commit 4671d551cf
37 changed files with 188 additions and 291 deletions

View File

@@ -6,16 +6,15 @@ const path = require('path');
// Create an object of all benchmark scripts
const benchmarks = {};
fs.readdirSync(__dirname)
.filter((name) => {
return name !== 'fixtures' &&
fs.statSync(path.resolve(__dirname, name)).isDirectory();
})
.filter((name) => fs.statSync(path.resolve(__dirname, name)).isDirectory())
.forEach((category) => {
benchmarks[category] = fs.readdirSync(path.resolve(__dirname, category))
.filter((filename) => filename[0] !== '.' && filename[0] !== '_');
});
function CLI(usage, settings) {
if (!(this instanceof CLI)) return new CLI(usage, settings);
if (process.argv.length < 3) {
this.abort(usage); // Abort will exit the process
}
@@ -23,7 +22,6 @@ function CLI(usage, settings) {
this.usage = usage;
this.optional = {};
this.items = [];
this.test = false;
for (const argName of settings.arrayArgs) {
this.optional[argName] = [];
@@ -36,7 +34,7 @@ function CLI(usage, settings) {
if (arg === '--') {
// Only items can follow --
mode = 'item';
} else if (mode === 'both' && arg[0] === '-') {
} else if ('both' === mode && arg[0] === '-') {
// Optional arguments declaration
if (arg[1] === '-') {
@@ -63,8 +61,6 @@ function CLI(usage, settings) {
// The next value can be either an option or an item
mode = 'both';
} else if (arg === 'test') {
this.test = true;
} else if (['both', 'item'].includes(mode)) {
// item arguments
this.items.push(arg);
@@ -87,15 +83,9 @@ CLI.prototype.abort = function(msg) {
CLI.prototype.benchmarks = function() {
const paths = [];
if (this.items.includes('all')) {
this.items = Object.keys(benchmarks);
}
for (const category of this.items) {
if (benchmarks[category] === undefined) {
console.error(`The "${category}" category does not exist.`);
process.exit(1);
}
if (benchmarks[category] === undefined)
continue;
for (const scripts of benchmarks[category]) {
if (this.shouldSkip(scripts)) continue;

View File

@@ -43,8 +43,9 @@ class AutocannonBenchmarker {
}
if (!result || !result.requests || !result.requests.average) {
return undefined;
} else {
return result.requests.average;
}
return result.requests.average;
}
}
@@ -76,8 +77,9 @@ class WrkBenchmarker {
const throughput = match && +match[1];
if (!isFinite(throughput)) {
return undefined;
} else {
return throughput;
}
return throughput;
}
}
@@ -87,8 +89,7 @@ class WrkBenchmarker {
*/
class TestDoubleBenchmarker {
constructor(type) {
// `type` is the type of benchmarker. Possible values are 'http' and
// 'http2'.
// `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);
@@ -96,11 +97,10 @@ class TestDoubleBenchmarker {
}
create(options) {
const env = {
const env = Object.assign({
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,14 +189,13 @@ http_benchmarkers.forEach((benchmarker) => {
});
exports.run = function(options, callback) {
options = {
options = Object.assign({
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.`));
@@ -213,7 +212,6 @@ exports.run = function(options, callback) {
'is not installed'));
return;
}
process.env.duration = process.env.duration || options.duration || 5;
const benchmarker_start = process.hrtime();
@@ -222,8 +220,7 @@ exports.run = function(options, callback) {
child.stderr.pipe(process.stderr);
let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => stdout += chunk);
child.stdout.on('data', (chunk) => stdout += chunk.toString());
child.once('close', (code) => {
const elapsed = process.hrtime(benchmarker_start);

View File

@@ -7,7 +7,7 @@ if (!['http', 'http2'].includes(myModule)) {
const http = require(myModule);
const duration = +process.env.duration;
const duration = process.env.duration || 0;
const url = process.env.test_url;
const start = process.hrtime();
@@ -18,15 +18,13 @@ function request(res, client) {
res.on('error', () => {});
res.on('end', () => {
throughput++;
const [sec, nanosec] = process.hrtime(start);
const ms = sec * 1000 + nanosec / 1e6;
if (ms < duration * 1000) {
const diff = process.hrtime(start);
if (duration > 0 && diff[0] < duration) {
run();
} else {
console.log(JSON.stringify({ throughput }));
if (client) {
client.destroy();
process.exit(0);
}
}
});
@@ -35,7 +33,7 @@ function request(res, client) {
function run() {
if (http.get) { // HTTP
http.get(url, request);
} else { // HTTP/2
} else { // HTTP/2
const client = http.connect(url);
client.on('error', (e) => { throw e; });
request(client.request(), client);

View File

@@ -3,11 +3,10 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'],
connections: [50, 500],
duration: 5
connections: [50, 500]
});
function main({ asyncHooks, connections, duration }) {
function main({ asyncHooks, connections }) {
if (asyncHooks !== 'none') {
let hooks = {
init() {},
@@ -34,7 +33,6 @@ function main({ asyncHooks, connections, duration }) {
bench.http({
connections,
path,
duration
}, () => {
server.close();
});

View File

@@ -25,8 +25,6 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
len: [64 * 1024 * 1024],
n: [32]
}, {
test: { len: 256 }
});
function main({ n, len }) {

View File

@@ -7,8 +7,6 @@ const bench = common.createBenchmark(main, {
method: ['swap16', 'swap32', 'swap64'/* , 'htons', 'htonl', 'htonll' */],
len: [64, 256, 768, 1024, 2056, 8192],
n: [1e6]
}, {
test: { len: 16 }
});
// The htons and htonl methods below are used to benchmark the

View File

@@ -4,83 +4,43 @@ const child_process = require('child_process');
const http_benchmarkers = require('./_http-benchmarkers.js');
class Benchmark {
// Used to make sure a benchmark only start a timer once
#started = false;
// Indicate that the benchmark ended
#ended = false;
// Holds process.hrtime value
#time = [0, 0];
// Use the file name as the name of the benchmark
name = require.main.filename.slice(__dirname.length + 1);
// Execution arguments i.e. flags used to run the jobs
flags = process.env.NODE_BENCHMARK_FLAGS ?
process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) :
[];
constructor(fn, configs, options = {}) {
constructor(fn, configs, options) {
// Use the file name as the name of the benchmark
this.name = require.main.filename.slice(__dirname.length + 1);
// Parse job-specific configuration from the command line arguments
const argv = process.argv.slice(2);
const parsed_args = this._parseArgs(argv, configs, options);
const parsed_args = this._parseArgs(process.argv.slice(2), configs);
this.options = parsed_args.cli;
this.extra_options = parsed_args.extra;
if (options.flags) {
this.flags = this.flags.concat(options.flags);
}
// The configuration list as a queue of jobs
this.queue = this._queue(this.options);
// The configuration of the current job, head of the queue
this.config = this.queue[0];
// Execution arguments i.e. flags used to run the jobs
this.flags = [];
if (options && options.flags) {
this.flags = this.flags.concat(options.flags);
}
if (process.env.NODE_BENCHMARK_FLAGS) {
const flags = process.env.NODE_BENCHMARK_FLAGS.split(/\s+/);
this.flags = this.flags.concat(flags);
}
// Holds process.hrtime value
this._time = [0, 0];
// Used to make sure a benchmark only start a timer once
this._started = false;
this._ended = false;
process.nextTick(() => {
if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) {
fn(this.config);
} else {
// _run will use fork() to create a new process for each configuration
// combination.
this._run();
}
});
// this._run will use fork() to create a new process for each configuration
// combination.
if (process.env.hasOwnProperty('NODE_RUN_BENCHMARK_FN')) {
process.nextTick(() => fn(this.config));
} else {
process.nextTick(() => this._run());
}
}
_parseArgs(argv, configs, options) {
_parseArgs(argv, configs) {
const cliOptions = {};
// Check for the test mode first.
const testIndex = argv.indexOf('--test');
if (testIndex !== -1) {
for (const [key, rawValue] of Object.entries(configs)) {
let value = Array.isArray(rawValue) ? rawValue[0] : rawValue;
// Set numbers to one by default to reduce the runtime.
if (typeof value === 'number') {
if (key === 'dur' || key === 'duration') {
value = 0.05;
} else if (value > 1) {
value = 1;
}
}
cliOptions[key] = [value];
}
// Override specific test options.
if (options.test) {
for (const [key, value] of Object.entries(options.test)) {
cliOptions[key] = Array.isArray(value) ? value : [value];
}
}
argv.splice(testIndex, 1);
} else {
// Accept single values instead of arrays.
for (const [key, value] of Object.entries(configs)) {
if (!Array.isArray(value))
configs[key] = [value];
}
}
const extraOptions = {};
const validArgRE = /^(.+?)=([\s\S]*)$/;
// Parse configuration arguments
@@ -90,43 +50,45 @@ class Benchmark {
console.error(`bad argument: ${arg}`);
process.exit(1);
}
const [, key, value] = match;
if (Object.prototype.hasOwnProperty.call(configs, key)) {
if (!cliOptions[key])
cliOptions[key] = [];
cliOptions[key].push(
// Infer the type from the config object and parse accordingly
typeof configs[key][0] === 'number' ? +value : value
);
const config = match[1];
if (configs[config]) {
// Infer the type from the config object and parse accordingly
const isNumber = typeof configs[config][0] === 'number';
const value = isNumber ? +match[2] : match[2];
if (!cliOptions[config])
cliOptions[config] = [];
cliOptions[config].push(value);
} else {
extraOptions[key] = value;
extraOptions[config] = match[2];
}
}
return { cli: { ...configs, ...cliOptions }, extra: extraOptions };
return { cli: Object.assign({}, configs, cliOptions), extra: extraOptions };
}
_queue(options) {
const queue = [];
const keys = Object.keys(options);
// Perform a depth-first walk through all options to generate a
// Perform a depth-first walk though all options to generate a
// configuration list that contains all combinations.
function recursive(keyIndex, prevConfig) {
const key = keys[keyIndex];
const values = options[key];
const type = typeof values[0];
for (const value of values) {
if (typeof value !== 'number' && typeof value !== 'string') {
throw new TypeError(
`configuration "${key}" had type ${typeof value}`);
}
if (typeof value !== typeof values[0]) {
if (typeof value !== type) {
// This is a requirement for being able to consistently and
// predictably parse CLI provided configuration values.
throw new TypeError(`configuration "${key}" has mixed types`);
}
const currConfig = { [key]: value, ...prevConfig };
const currConfig = Object.assign({ [key]: value }, prevConfig);
if (keyIndex + 1 < keys.length) {
recursive(keyIndex + 1, currConfig);
@@ -146,11 +108,12 @@ class Benchmark {
}
http(options, cb) {
const http_options = { ...options };
const self = this;
const http_options = Object.assign({ }, options);
http_options.benchmarker = http_options.benchmarker ||
this.config.benchmarker ||
this.extra_options.benchmarker ||
http_benchmarkers.default_http_benchmarker;
self.config.benchmarker ||
self.extra_options.benchmarker ||
exports.default_http_benchmarker;
http_benchmarkers.run(
http_options, (error, code, used_benchmarker, result, elapsed) => {
if (cb) {
@@ -160,13 +123,14 @@ class Benchmark {
console.error(error);
process.exit(code || 1);
}
this.config.benchmarker = used_benchmarker;
this.report(result, elapsed);
self.config.benchmarker = used_benchmarker;
self.report(result, elapsed);
}
);
}
_run() {
const self = this;
// If forked, report to the parent.
if (process.send) {
process.send({
@@ -176,27 +140,27 @@ class Benchmark {
});
}
const recursive = (queueIndex) => {
const config = this.queue[queueIndex];
(function recursive(queueIndex) {
const config = self.queue[queueIndex];
// Set NODE_RUN_BENCHMARK_FN to indicate that the child shouldn't
// construct a configuration queue, but just execute the benchmark
// function.
const childEnv = { ...process.env };
const childEnv = Object.assign({}, process.env);
childEnv.NODE_RUN_BENCHMARK_FN = '';
// Create configuration arguments
const childArgs = [];
for (const [key, value] of Object.entries(config)) {
childArgs.push(`${key}=${value}`);
for (const key of Object.keys(config)) {
childArgs.push(`${key}=${config[key]}`);
}
for (const [key, value] of Object.entries(this.extra_options)) {
childArgs.push(`${key}=${value}`);
for (const key of Object.keys(self.extra_options)) {
childArgs.push(`${key}=${self.extra_options[key]}`);
}
const child = child_process.fork(require.main.filename, childArgs, {
env: childEnv,
execArgv: this.flags.concat(process.execArgv),
execArgv: self.flags.concat(process.execArgv),
});
child.on('message', sendResult);
child.on('close', (code) => {
@@ -204,31 +168,29 @@ class Benchmark {
process.exit(code);
}
if (queueIndex + 1 < this.queue.length) {
if (queueIndex + 1 < self.queue.length) {
recursive(queueIndex + 1);
}
});
};
recursive(0);
})(0);
}
start() {
if (this.#started) {
if (this._started) {
throw new Error('Called start more than once in a single benchmark');
}
this.#started = true;
this.#time = process.hrtime();
this._started = true;
this._time = process.hrtime();
}
end(operations) {
// Get elapsed time now and do error checking later for accuracy.
const elapsed = process.hrtime(this.#time);
const elapsed = process.hrtime(this._time);
if (!this.#started) {
if (!this._started) {
throw new Error('called end without start');
}
if (this.#ended) {
if (this._ended) {
throw new Error('called end multiple times');
}
if (typeof operations !== 'number') {
@@ -244,7 +206,7 @@ class Benchmark {
elapsed[1] = 1;
}
this.#ended = true;
this._ended = true;
const time = elapsed[0] + elapsed[1] / 1e9;
const rate = operations / time;
this.report(rate, elapsed);
@@ -254,7 +216,7 @@ class Benchmark {
sendResult({
name: this.name,
conf: this.config,
rate,
rate: rate,
time: elapsed[0] + elapsed[1] / 1e9,
type: 'report',
});
@@ -372,7 +334,6 @@ function bakeUrlData(type, e = 0, withBase = false, asUrl = false) {
}
module.exports = {
Benchmark,
PORT: http_benchmarkers.PORT,
bakeUrlData,
binding(bindingName) {
@@ -388,6 +349,8 @@ module.exports = {
createBenchmark(fn, configs, options) {
return new Benchmark(fn, configs, options);
},
// Benchmark an http server.
default_http_benchmarker: http_benchmarkers.default_http_benchmarker,
sendResult,
searchParams,
urlDataTypes: Object.keys(urls).concat(['wpt']),

View File

@@ -9,7 +9,7 @@ const BenchmarkProgress = require('./_benchmark_progress.js');
//
// Parse arguments
//
const cli = new CLI(`usage: ./node compare.js [options] [--] <category> ...
const cli = CLI(`usage: ./node compare.js [options] [--] <category> ...
Run each benchmark in the <category> directory many times using two different
node versions. More than one <category> directory can be specified.
The output is formatted as csv, which can be processed using for

View File

@@ -7,8 +7,6 @@ const bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'],
len: [2, 1024, 102400, 1024 * 1024],
api: ['legacy', 'stream']
}, {
flags: ['--no-warnings']
});
function main({ api, cipher, type, len, writes }) {

View File

@@ -11,18 +11,19 @@ tmpdir.refresh();
const filename = path.resolve(tmpdir.path,
`.removeme-benchmark-garbage-${process.pid}`);
let encodingType, encoding, size, filesize;
const bench = common.createBenchmark(main, {
encodingType: ['buf', 'asc', 'utf'],
filesize: [1000 * 1024],
highWaterMark: [1024, 4096, 65535, 1024 * 1024],
n: 1024
filesize: [1000 * 1024 * 1024],
size: [1024, 4096, 65535, 1024 * 1024]
});
function main(conf) {
const { encodingType, highWaterMark, filesize } = conf;
let { n } = conf;
encodingType = conf.encodingType;
size = conf.size;
filesize = conf.filesize;
let encoding = '';
switch (encodingType) {
case 'buf':
encoding = null;
@@ -37,38 +38,14 @@ function main(conf) {
throw new Error(`invalid encodingType: ${encodingType}`);
}
// Make file
const buf = Buffer.allocUnsafe(filesize);
if (encoding === 'utf8') {
// ü
for (let i = 0; i < buf.length; i++) {
buf[i] = i % 2 === 0 ? 0xC3 : 0xBC;
}
} else if (encoding === 'ascii') {
buf.fill('a');
} else {
buf.fill('x');
}
try { fs.unlinkSync(filename); } catch {}
const ws = fs.createWriteStream(filename);
ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n));
ws.on('drain', write);
write();
function write() {
do {
n--;
} while (false !== ws.write(buf) && n > 0);
if (n === 0)
ws.end();
}
makeFile();
}
function runTest(filesize, highWaterMark, encoding, n) {
assert(fs.statSync(filename).size === filesize * n);
function runTest() {
assert(fs.statSync(filename).size === filesize);
const rs = fs.createReadStream(filename, {
highWaterMark,
encoding
highWaterMark: size,
encoding: encoding
});
rs.on('open', () => {
@@ -86,3 +63,31 @@ function runTest(filesize, highWaterMark, encoding, n) {
bench.end(bytes / (1024 * 1024));
});
}
function makeFile() {
const buf = Buffer.allocUnsafe(filesize / 1024);
if (encoding === 'utf8') {
// ü
for (let i = 0; i < buf.length; i++) {
buf[i] = i % 2 === 0 ? 0xC3 : 0xBC;
}
} else if (encoding === 'ascii') {
buf.fill('a');
} else {
buf.fill('x');
}
try { fs.unlinkSync(filename); } catch {}
let w = 1024;
const ws = fs.createWriteStream(filename);
ws.on('close', runTest);
ws.on('drain', write);
write();
function write() {
do {
w--;
} while (false !== ws.write(buf) && w > 0);
if (w === 0)
ws.end();
}
}

View File

@@ -14,12 +14,12 @@ const filename = path.resolve(tmpdir.path,
`.removeme-benchmark-garbage-${process.pid}`);
const bench = common.createBenchmark(main, {
duration: [5],
dur: [5],
len: [1024, 16 * 1024 * 1024],
concurrent: [1, 10]
});
function main({ len, duration, concurrent }) {
function main({ len, dur, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
@@ -33,7 +33,7 @@ function main({ len, duration, concurrent }) {
bench.end(reads);
try { fs.unlinkSync(filename); } catch {}
process.exit(0);
}, duration * 1000);
}, dur * 1000);
function read() {
fs.readFile(filename, afterRead);

View File

@@ -13,11 +13,10 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1, 4, 8, 16],
len: [1, 64, 256],
c: [100],
duration: 5
c: [100]
});
function main({ len, n, c, duration }) {
function main({ len, n, c }) {
const http = require('http');
const chunk = Buffer.alloc(len, '8');
@@ -34,8 +33,7 @@ function main({ len, n, c, duration }) {
server.listen(common.PORT, () => {
bench.http({
connections: c,
duration
connections: c
}, () => {
server.close();
});

View File

@@ -9,15 +9,14 @@ if (cluster.isMaster) {
// Unicode confuses ab on os x.
type: ['bytes', 'buffer'],
len: [4, 1024, 102400],
c: [50, 500],
duration: 5,
c: [50, 500]
});
} else {
const port = parseInt(process.env.PORT || PORT);
require('../fixtures/simple-http-server.js').listen(port);
}
function main({ type, len, c, duration }) {
function main({ type, len, c }) {
process.env.PORT = PORT;
let workers = 0;
const w1 = cluster.fork();
@@ -33,8 +32,7 @@ function main({ type, len, c, duration }) {
bench.http({
path: path,
connections: c,
duration
connections: c
}, () => {
w1.destroy();
w2.destroy();

View File

@@ -14,11 +14,10 @@ const bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'],
len: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024],
c: [100],
method: ['write', 'end'],
duration: 5
method: ['write', 'end']
});
function main({ len, type, method, c, duration }) {
function main({ len, type, method, c }) {
const http = require('http');
let chunk;
switch (type) {
@@ -50,8 +49,7 @@ function main({ len, type, method, c, duration }) {
server.listen(common.PORT, () => {
bench.http({
connections: c,
duration
connections: c
}, () => {
server.close();
});

View File

@@ -6,10 +6,9 @@ const http = require('http');
const bench = common.createBenchmark(main, {
n: [10, 1000],
len: [1, 100],
duration: 5
});
function main({ len, n, duration }) {
function main({ len, n }) {
const headers = {
'Connection': 'keep-alive',
'Transfer-Encoding': 'chunked',
@@ -30,8 +29,7 @@ function main({ len, n, duration }) {
server.listen(common.PORT, () => {
bench.http({
path: '/',
connections: 10,
duration
connections: 10
}, () => {
server.close();
});

View File

@@ -3,13 +3,12 @@ const common = require('../common.js');
const http = require('http');
const bench = common.createBenchmark(main, {
connections: [50], // Concurrent connections
headers: [20], // Number of header lines to append after the common headers
w: [0, 6], // Amount of trailing whitespace
duration: 5
c: [50], // Concurrent connections
n: [20], // Number of header lines to append after the common headers
w: [0, 6], // Amount of trailing whitespace
});
function main({ connections, headers, w, duration }) {
function main({ c, n, w }) {
const server = http.createServer((req, res) => {
res.end();
});
@@ -22,7 +21,7 @@ function main({ connections, headers, w, duration }) {
'Date': new Date().toString(),
'Cache-Control': 'no-cache'
};
for (let i = 0; i < headers; i++) {
for (let i = 0; i < n; i++) {
// Note:
// - autocannon does not send header values with OWS
// - wrk can only send trailing OWS. This is a side-effect of wrk
@@ -32,9 +31,8 @@ function main({ connections, headers, w, duration }) {
}
bench.http({
path: '/',
connections,
headers,
duration
connections: c,
headers
}, () => {
server.close();
});

View File

@@ -3,8 +3,7 @@ const common = require('../common.js');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
res: ['normal', 'setHeader', 'setHeaderWH'],
duration: 5
res: ['normal', 'setHeader', 'setHeaderWH']
});
const type = 'bytes';
@@ -16,17 +15,16 @@ const c = 50;
// normal: writeHead(status, {...})
// setHeader: statusCode = status, setHeader(...) x2
// setHeaderWH: setHeader(...), writeHead(status, ...)
function main({ res, duration }) {
function main({ res }) {
process.env.PORT = PORT;
const server = require('../fixtures/simple-http-server.js')
.listen(PORT)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`;
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;
bench.http({
path: path,
connections: c,
duration
connections: c
}, () => {
server.close();
});

View File

@@ -7,20 +7,18 @@ const bench = common.createBenchmark(main, {
len: [4, 1024, 102400],
chunks: [1, 4],
c: [50, 500],
chunkedEnc: [1, 0],
duration: 5
chunkedEnc: [1, 0]
});
function main({ type, len, chunks, c, chunkedEnc, duration }) {
function main({ type, len, chunks, c, chunkedEnc, res }) {
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;
bench.http({
path,
connections: c,
duration
path: path,
connections: c
}, () => {
server.close();
});

View File

@@ -9,11 +9,10 @@ const bench = common.createBenchmark(main, {
requests: [100, 1000, 5000],
streams: [1, 10, 20, 40, 100, 200],
clients: [2],
benchmarker: ['test-double-http2'],
duration: 5
benchmarker: ['h2load']
}, { flags: ['--no-warnings'] });
function main({ requests, streams, clients, duration }) {
function main({ requests, streams, clients }) {
const http2 = require('http2');
const server = http2.createServer();
server.on('request', (req, res) => {
@@ -30,8 +29,7 @@ function main({ requests, streams, clients, duration }) {
requests,
maxConcurrentStreams: streams,
clients,
threads: clients,
duration
threads: clients
}, () => { server.close(); });
});
}

View File

@@ -10,11 +10,10 @@ const bench = common.createBenchmark(main, {
requests: [100, 1000, 5000],
streams: [1, 10, 20, 40, 100, 200],
clients: [2],
benchmarker: ['test-double-http2'],
duration: 5
benchmarker: ['h2load']
}, { flags: ['--no-warnings'] });
function main({ requests, streams, clients, duration }) {
function main({ requests, streams, clients }) {
fs.open(file, 'r', (err, fd) => {
if (err)
throw err;
@@ -31,7 +30,6 @@ function main({ requests, streams, clients, duration }) {
requests,
maxConcurrentStreams: streams,
clients,
duration,
threads: clients
}, () => server.close());
});

View File

@@ -9,11 +9,10 @@ const bench = common.createBenchmark(main, {
requests: [100, 1000, 5000],
streams: [1, 10, 20, 40, 100, 200],
clients: [2],
benchmarker: ['test-double-http2'],
duration: 5
benchmarker: ['h2load']
}, { flags: ['--no-warnings'] });
function main({ requests, streams, clients, duration }) {
function main({ requests, streams, clients }) {
const http2 = require('http2');
const server = http2.createServer();
server.on('stream', (stream) => {
@@ -28,7 +27,6 @@ function main({ requests, streams, clients, duration }) {
requests,
maxConcurrentStreams: streams,
clients,
duration,
threads: clients
}, () => { server.close(); });
});

View File

@@ -6,11 +6,10 @@ const bench = common.createBenchmark(main, {
streams: [100, 200, 1000],
length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024],
size: [100000],
benchmarker: ['test-double-http2'],
duration: 5
benchmarker: ['h2load']
}, { flags: ['--no-warnings'] });
function main({ streams, length, size, duration }) {
function main({ streams, length, size }) {
const http2 = require('http2');
const server = http2.createServer();
server.on('stream', (stream) => {
@@ -30,7 +29,6 @@ function main({ streams, length, size, duration }) {
bench.http({
path: '/',
requests: 10000,
duration,
maxConcurrentStreams: streams,
}, () => { server.close(); });
});

View File

@@ -6,11 +6,7 @@ const bench = common.createBenchmark(main, {
n: [100000],
method: ['trace', 'isTraceCategoryEnabled']
}, {
flags: [
'--expose-internals',
'--no-warnings',
'--trace-event-categories', 'foo',
]
flags: ['--expose-internals', '--trace-event-categories', 'foo']
});
const {

View File

@@ -9,8 +9,6 @@ const bench = common.createBenchmark(main, {
len: [64, 102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 }
});
var chunk;

View File

@@ -9,8 +9,6 @@ const bench = common.createBenchmark(main, {
len: [2, 64, 102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 1024 }
});
var chunk;

View File

@@ -10,8 +10,6 @@ const bench = common.createBenchmark(main, {
recvbuflen: [0, 64 * 1024, 1024 * 1024],
recvbufgenfn: ['true', 'false'],
dur: [5]
}, {
test: { sendchunklen: 256 }
});
var chunk;

View File

@@ -9,7 +9,6 @@ const bench = common.createBenchmark(main, {
type: ['utf', 'asc', 'buf'],
dur: [5],
}, {
test: { len: 64 },
flags: ['--expose-internals']
});

View File

@@ -12,10 +12,7 @@ const bench = common.createBenchmark(main, {
len: [102400, 1024 * 1024 * 16],
type: ['utf', 'asc', 'buf'],
dur: [5]
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ]
});
}, { flags: [ '--expose-internals', '--no-warnings' ] });
function main({ dur, len, type }) {
const {

View File

@@ -13,7 +13,6 @@ const bench = common.createBenchmark(main, {
type: ['utf', 'asc', 'buf'],
dur: [5]
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ]
});

View File

@@ -13,7 +13,6 @@ const bench = common.createBenchmark(main, {
type: ['utf', 'asc', 'buf'],
dur: [5]
}, {
test: { len: 1024 },
flags: [ '--expose-internals', '--no-warnings' ]
});

View File

@@ -4,7 +4,7 @@ const path = require('path');
const fork = require('child_process').fork;
const CLI = require('./_cli.js');
const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
Run each benchmark in the <category> directory a single time, more than one
<category> directory can be specified.
@@ -14,9 +14,6 @@ const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
repeated)
--set variable=value set benchmark variable (can be repeated)
--format [simple|csv] optional value that specifies the output format
test only run a single configuration from the options
matrix
all each benchmark category is run one after the other
`, { arrayArgs: ['set', 'filter', 'exclude'] });
const benchmarks = cli.benchmarks();
@@ -40,11 +37,7 @@ if (format === 'csv') {
(function recursive(i) {
const filename = benchmarks[i];
const child = fork(
path.resolve(__dirname, filename),
cli.test ? ['--test'] : [],
cli.optional.set
);
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
if (format !== 'csv') {
console.log();
@@ -58,10 +51,10 @@ if (format === 'csv') {
// Construct configuration string, " A=a, B=b, ..."
let conf = '';
for (const key of Object.keys(data.conf)) {
if (conf !== '')
conf += ' ';
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
}
// Delete first space of the configuration
conf = conf.slice(1);
if (format === 'csv') {
// Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""');

View File

@@ -7,7 +7,7 @@ const CLI = require('./_cli.js');
//
// Parse arguments
//
const cli = new CLI(`usage: ./node scatter.js [options] [--] <filename>
const cli = CLI(`usage: ./node scatter.js [options] [--] <filename>
Run the benchmark script <filename> many times and output the rate (ops/s)
together with the benchmark variables as a csv.

View File

@@ -4,8 +4,6 @@ const bench = common.createBenchmark(main, {
dur: [5],
securing: ['SecurePair', 'TLSSocket', 'clear'],
size: [2, 100, 1024, 1024 * 1024]
}, {
flags: ['--no-warnings']
});
const fixtures = require('../../test/common/fixtures');

View File

@@ -31,7 +31,7 @@ const bench = common.createBenchmark(main, {
argument: ['true', 'false-primitive', 'false-object'],
n: [1e5]
}, {
flags: ['--expose-internals', '--no-warnings']
flags: ['--expose-internals']
});
function main({ type, argument, version, n }) {

View File

@@ -519,8 +519,7 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
kb: [64, 128, 256, 1024],
connections: [100, 500],
duration: 5
connections: [100, 500]
});
function main(conf) {
@@ -547,8 +546,8 @@ Supported options keys are:
* `path` - defaults to `/`
* `connections` - number of concurrent connections to use, defaults to 100
* `duration` - duration of the benchmark in seconds, defaults to 10
* `benchmarker` - benchmarker to use, defaults to the first available http
benchmarker
* `benchmarker` - benchmarker to use, defaults to
`common.default_http_benchmarker`
[autocannon]: https://github.com/mcollina/autocannon
[wrk]: https://github.com/wg/wrk

View File

@@ -8,11 +8,6 @@ const bench = common.createBenchmark(main, {
duration: [5],
type: ['string', 'buffer'],
algorithm: ['gzip', 'brotli']
}, {
test: {
inputLen: 1024,
duration: 0.2
}
});
function main({ inputLen, duration, type, algorithm }) {

View File

@@ -8,8 +8,13 @@ const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
function runBenchmark(name, env) {
const argv = ['test'];
function runBenchmark(name, args, env) {
const argv = [];
for (let i = 0; i < args.length; i++) {
argv.push('--set');
argv.push(args[i]);
}
argv.push(name);