Skip to content

Commit bb58fcd

Browse files
committed
http,net,stream: reconcile write and parser paths
Signed-off-by: GetThatCookie <NimmenKeks@gmx.de>
1 parent 790260a commit bb58fcd

15 files changed

Lines changed: 403 additions & 170 deletions

benchmark/common.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Benchmark {
2626

2727
// Parse job-specific configuration from the command line arguments
2828
const argv = process.argv.slice(2);
29-
const parsed_args = this._parseArgs([...argv], configs, options);
29+
const parsed_args = this._parseArgs(argv, configs, options);
3030

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

4040
for (const groupName of groupNames) {
41-
const groupConfig = Array.isArray(configs[groupName]) ?
42-
configs[groupName][0] : configs[groupName];
43-
const config = { ...groupConfig, group: groupName };
44-
const parsed_args = this._parseArgs([...argv], config, options);
41+
const config = { ...configs[groupName][0], group: groupName };
42+
const parsed_args = this._parseArgs(argv, config, options);
4543

4644
this.options = parsed_args.cli;
4745
this.extra_options = parsed_args.extra;
@@ -223,9 +221,6 @@ class Benchmark {
223221
// function.
224222
const childEnv = { ...process.env };
225223
childEnv.NODE_RUN_BENCHMARK_FN = '';
226-
if (this.originalOptions.byGroups) {
227-
childEnv.NODE_RUN_BENCHMARK_GROUPS = config.group;
228-
}
229224

230225
// Create configuration arguments
231226
const childArgs = [];

benchmark/http/cork.js

Lines changed: 78 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,117 +3,99 @@
33
const common = require('../common.js');
44
const protocols = process.versions.openssl ? ['http', 'https'] : ['http'];
55

6-
const configs = {
7-
sameTurn: [{
8-
type: ['bytes', 'buffer', 'uint8array'],
9-
len: [64, 1024],
10-
chunks: [1, 2, 4, 16],
11-
mode: ['auto', 'explicit'],
12-
transfer: ['chunked', 'length'],
13-
protocol: protocols,
14-
producer: ['sync'],
15-
callback: [0],
16-
c: [50],
17-
duration: 5,
18-
}],
19-
streaming: [{
20-
type: ['bytes', 'buffer', 'uint8array'],
21-
len: [64, 1024],
22-
chunks: [4],
23-
mode: ['auto'],
24-
transfer: ['chunked'],
25-
protocol: protocols,
26-
producer: ['nextTick', 'microtask', 'immediate'],
27-
callback: [0],
28-
c: [50],
29-
duration: 5,
30-
}],
31-
callbacks: [{
32-
type: ['bytes', 'buffer', 'uint8array'],
33-
len: [64],
34-
chunks: [4, 16],
35-
mode: ['auto', 'explicit'],
36-
transfer: ['chunked'],
37-
protocol: protocols,
38-
producer: ['sync'],
39-
callback: [1],
40-
c: [50],
41-
duration: 5,
42-
}],
43-
fixedBody: [{
44-
type: ['bytes', 'buffer', 'uint8array'],
45-
total: [64 * 1024],
46-
chunks: [1, 4, 16, 128],
47-
mode: ['auto', 'explicit'],
48-
transfer: ['chunked'],
49-
protocol: protocols,
50-
producer: ['sync'],
51-
callback: [0],
52-
c: [50],
53-
duration: 5,
54-
}],
55-
largeChunks: [{
56-
type: ['bytes', 'buffer', 'uint8array'],
57-
len: [4 * 1024, 8 * 1024, 16 * 1024, 64 * 1024],
58-
chunks: [1, 4],
59-
mode: ['auto'],
60-
transfer: ['chunked'],
61-
protocol: protocols,
62-
producer: ['sync'],
63-
callback: [0],
64-
c: [50],
65-
duration: 5,
66-
}],
67-
concurrency: [{
68-
type: ['bytes'],
69-
len: [64],
70-
chunks: [4],
71-
mode: ['auto'],
72-
transfer: ['chunked'],
73-
protocol: protocols,
74-
producer: ['sync'],
75-
callback: [0],
76-
c: [1, 50, 500],
77-
duration: 5,
78-
}],
6+
const scenarios = {
7+
'end-64': {
8+
len: 64,
9+
chunks: 1,
10+
endChunk: true,
11+
},
12+
'end-1024': {
13+
len: 1024,
14+
chunks: 1,
15+
endChunk: true,
16+
},
17+
'end-1025': {
18+
len: 1025,
19+
chunks: 1,
20+
endChunk: true,
21+
},
22+
'auto-4': {
23+
len: 64,
24+
chunks: 4,
25+
},
26+
'auto-16': {
27+
len: 64,
28+
chunks: 16,
29+
},
30+
'explicit-16': {
31+
len: 64,
32+
chunks: 16,
33+
explicit: true,
34+
},
35+
'content-length-16': {
36+
len: 64,
37+
chunks: 16,
38+
contentLength: true,
39+
},
40+
'next-tick-4': {
41+
len: 64,
42+
chunks: 4,
43+
schedule: process.nextTick,
44+
},
45+
'callbacks-16': {
46+
len: 64,
47+
chunks: 16,
48+
callbacks: true,
49+
},
50+
'fixed-body-128': {
51+
len: 512,
52+
chunks: 128,
53+
},
54+
'large-16k': {
55+
len: 16 * 1024,
56+
chunks: 4,
57+
},
7958
};
8059

81-
const bench = common.createBenchmark(main, configs, { byGroups: true });
60+
const bench = common.createBenchmark(main, {
61+
type: ['string', 'buffer', 'uint8array'],
62+
scenario: Object.keys(scenarios),
63+
protocol: protocols,
64+
c: [50],
65+
duration: [5],
66+
});
8267

83-
function main({
84-
type,
85-
len,
86-
chunks,
87-
mode,
88-
transfer,
89-
protocol,
90-
producer,
91-
callback,
92-
c,
93-
duration,
94-
total,
95-
}) {
68+
function main({ type, scenario, protocol, c, duration }) {
69+
const {
70+
callbacks,
71+
chunks,
72+
contentLength,
73+
endChunk,
74+
explicit,
75+
len,
76+
schedule,
77+
} = scenarios[scenario];
9678
const transport = require(protocol);
97-
len ??= total / chunks;
98-
const chunk = type === 'bytes' ? 'a'.repeat(len) :
79+
const chunk = type === 'string' ? 'a'.repeat(len) :
9980
type === 'buffer' ? Buffer.alloc(len, 'a') :
10081
new Uint8Array(len).fill(0x61);
101-
const writeCallback = callback ? (err) => {
82+
const writeCallback = callbacks ? (err) => {
10283
if (err) throw err;
10384
} : undefined;
10485

105-
const schedule = producer === 'nextTick' ? process.nextTick :
106-
producer === 'microtask' ? queueMicrotask : setImmediate;
107-
10886
const onRequest = (req, res) => {
109-
if (transfer === 'length') {
87+
if (contentLength) {
11088
res.setHeader('Content-Length', len * chunks);
11189
}
112-
if (mode === 'explicit') {
90+
if (explicit) {
11391
res.cork();
11492
}
93+
if (endChunk) {
94+
res.end(chunk, writeCallback);
95+
return;
96+
}
11597

116-
if (producer === 'sync') {
98+
if (schedule === undefined) {
11799
for (let i = 0; i < chunks; i++) {
118100
res.write(chunk, writeCallback);
119101
}

benchmark/http2/compat.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ const fs = require('fs');
66
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');
77

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

16-
function main({ requests, streams, clients, duration }) {
18+
function main({ response, size, requests, streams, clients, duration }) {
1719
const http2 = require('http2');
20+
const body = 'a'.repeat(size);
1821
const server = http2.createServer();
1922
server.on('request', (req, res) => {
23+
if (response === 'end') {
24+
res.end(body);
25+
return;
26+
}
2027
const out = fs.createReadStream(file);
2128
res.setHeader('content-type', 'text/html');
2229
out.pipe(res);

0 commit comments

Comments
 (0)