Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
http,net,stream: reconcile write and parser paths
Signed-off-by: GetThatCookie <NimmenKeks@gmx.de>
  • Loading branch information
GetThatCookie committed Aug 3, 2026
commit bb58fcd99042e106108e261ff2670ef442605b96
11 changes: 3 additions & 8 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Benchmark {

// 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(argv, configs, options);

this.originalOptions = options;
this.options = parsed_args.cli;
Expand All @@ -38,10 +38,8 @@ class Benchmark {
const groupNames = process.env.NODE_RUN_BENCHMARK_GROUPS?.split(',') ?? Object.keys(configs);

for (const groupName of groupNames) {
const groupConfig = Array.isArray(configs[groupName]) ?
configs[groupName][0] : configs[groupName];
const config = { ...groupConfig, group: groupName };
const parsed_args = this._parseArgs([...argv], config, options);
const config = { ...configs[groupName][0], group: groupName };
const parsed_args = this._parseArgs(argv, config, options);

this.options = parsed_args.cli;
this.extra_options = parsed_args.extra;
Expand Down Expand Up @@ -223,9 +221,6 @@ class Benchmark {
// function.
const childEnv = { ...process.env };
childEnv.NODE_RUN_BENCHMARK_FN = '';
if (this.originalOptions.byGroups) {
childEnv.NODE_RUN_BENCHMARK_GROUPS = config.group;
}

// Create configuration arguments
const childArgs = [];
Expand Down
174 changes: 78 additions & 96 deletions benchmark/http/cork.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,117 +3,99 @@
const common = require('../common.js');
const protocols = process.versions.openssl ? ['http', 'https'] : ['http'];

const configs = {
sameTurn: [{
type: ['bytes', 'buffer', 'uint8array'],
len: [64, 1024],
chunks: [1, 2, 4, 16],
mode: ['auto', 'explicit'],
transfer: ['chunked', 'length'],
protocol: protocols,
producer: ['sync'],
callback: [0],
c: [50],
duration: 5,
}],
streaming: [{
type: ['bytes', 'buffer', 'uint8array'],
len: [64, 1024],
chunks: [4],
mode: ['auto'],
transfer: ['chunked'],
protocol: protocols,
producer: ['nextTick', 'microtask', 'immediate'],
callback: [0],
c: [50],
duration: 5,
}],
callbacks: [{
type: ['bytes', 'buffer', 'uint8array'],
len: [64],
chunks: [4, 16],
mode: ['auto', 'explicit'],
transfer: ['chunked'],
protocol: protocols,
producer: ['sync'],
callback: [1],
c: [50],
duration: 5,
}],
fixedBody: [{
type: ['bytes', 'buffer', 'uint8array'],
total: [64 * 1024],
chunks: [1, 4, 16, 128],
mode: ['auto', 'explicit'],
transfer: ['chunked'],
protocol: protocols,
producer: ['sync'],
callback: [0],
c: [50],
duration: 5,
}],
largeChunks: [{
type: ['bytes', 'buffer', 'uint8array'],
len: [4 * 1024, 8 * 1024, 16 * 1024, 64 * 1024],
chunks: [1, 4],
mode: ['auto'],
transfer: ['chunked'],
protocol: protocols,
producer: ['sync'],
callback: [0],
c: [50],
duration: 5,
}],
concurrency: [{
type: ['bytes'],
len: [64],
chunks: [4],
mode: ['auto'],
transfer: ['chunked'],
protocol: protocols,
producer: ['sync'],
callback: [0],
c: [1, 50, 500],
duration: 5,
}],
const scenarios = {
'end-64': {
len: 64,
chunks: 1,
endChunk: true,
},
'end-1024': {
len: 1024,
chunks: 1,
endChunk: true,
},
'end-1025': {
len: 1025,
chunks: 1,
endChunk: true,
},
'auto-4': {
len: 64,
chunks: 4,
},
'auto-16': {
len: 64,
chunks: 16,
},
'explicit-16': {
len: 64,
chunks: 16,
explicit: true,
},
'content-length-16': {
len: 64,
chunks: 16,
contentLength: true,
},
'next-tick-4': {
len: 64,
chunks: 4,
schedule: process.nextTick,
},
'callbacks-16': {
len: 64,
chunks: 16,
callbacks: true,
},
'fixed-body-128': {
len: 512,
chunks: 128,
},
'large-16k': {
len: 16 * 1024,
chunks: 4,
},
};

const bench = common.createBenchmark(main, configs, { byGroups: true });
const bench = common.createBenchmark(main, {
type: ['string', 'buffer', 'uint8array'],
scenario: Object.keys(scenarios),
protocol: protocols,
c: [50],
duration: [5],
});

function main({
type,
len,
chunks,
mode,
transfer,
protocol,
producer,
callback,
c,
duration,
total,
}) {
function main({ type, scenario, protocol, c, duration }) {
const {
callbacks,
chunks,
contentLength,
endChunk,
explicit,
len,
schedule,
} = scenarios[scenario];
const transport = require(protocol);
len ??= total / chunks;
const chunk = type === 'bytes' ? 'a'.repeat(len) :
const chunk = type === 'string' ? 'a'.repeat(len) :
type === 'buffer' ? Buffer.alloc(len, 'a') :
new Uint8Array(len).fill(0x61);
const writeCallback = callback ? (err) => {
const writeCallback = callbacks ? (err) => {
if (err) throw err;
} : undefined;

const schedule = producer === 'nextTick' ? process.nextTick :
producer === 'microtask' ? queueMicrotask : setImmediate;

const onRequest = (req, res) => {
if (transfer === 'length') {
if (contentLength) {
res.setHeader('Content-Length', len * chunks);
}
if (mode === 'explicit') {
if (explicit) {
res.cork();
}
if (endChunk) {
res.end(chunk, writeCallback);
return;
}

if (producer === 'sync') {
if (schedule === undefined) {
for (let i = 0; i < chunks; i++) {
res.write(chunk, writeCallback);
}
Expand Down
9 changes: 8 additions & 1 deletion benchmark/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ const fs = require('fs');
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');

const bench = common.createBenchmark(main, {
response: ['end', 'pipe'],
size: [64],
requests: [100, 1000, 5000],
streams: [1, 10, 20, 40, 100, 200],
clients: [2],
benchmarker: ['test-double-http2'],
duration: 5,
}, { flags: ['--no-warnings'] });

function main({ requests, streams, clients, duration }) {
function main({ response, size, requests, streams, clients, duration }) {
const http2 = require('http2');
const body = 'a'.repeat(size);
const server = http2.createServer();
server.on('request', (req, res) => {
if (response === 'end') {
res.end(body);
return;
}
const out = fs.createReadStream(file);
res.setHeader('content-type', 'text/html');
out.pipe(res);
Expand Down
Loading