Skip to content

Commit 1abff07

Browse files
authored
stream: bump default highWaterMark
This should give a performance boost accross the board. Given that the old limit is a decod old and memory capacity has doubled many times since I think it is appropriate to slightly bump the default limit. PR-URL: #52037 Refs: #46608 Refs: #50120 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 57d2e48 commit 1abff07

18 files changed

+34
-19
lines changed

benchmark/net/net-c2s.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const net = require('net');
66
const PORT = common.PORT;
77

88
const bench = common.createBenchmark(main, {
9-
len: [64, 102400, 1024 * 1024 * 16],
9+
len: [64, 102400, 1024 * 64 * 16],
1010
type: ['utf', 'asc', 'buf'],
1111
dur: [5],
1212
}, {

benchmark/net/net-pipe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const net = require('net');
66
const PORT = common.PORT;
77

88
const bench = common.createBenchmark(main, {
9-
len: [2, 64, 102400, 1024 * 1024 * 16],
9+
len: [2, 64, 102400, 1024 * 64 * 16],
1010
type: ['utf', 'asc', 'buf'],
1111
dur: [5],
1212
}, {

benchmark/net/net-s2c.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const common = require('../common.js');
55
const PORT = common.PORT;
66

77
const bench = common.createBenchmark(main, {
8-
sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 1024 * 1024],
8+
sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 64 * 1024],
99
type: ['utf', 'asc', 'buf'],
1010
recvbuflen: [0, 64 * 1024, 1024 * 1024],
1111
recvbufgenfn: ['true', 'false'],

benchmark/net/net-wrap-js-stream-passthrough.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const common = require('../common.js');
55
const { PassThrough } = require('stream');
66

77
const bench = common.createBenchmark(main, {
8-
len: [64, 102400, 1024 * 1024 * 16],
8+
len: [64, 102400, 1024 * 64 * 16],
99
type: ['utf', 'asc', 'buf'],
1010
dur: [5],
1111
}, {

benchmark/net/tcp-raw-c2s.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const util = require('util');
99
// run the function with those settings.
1010
// if not, then queue up a bunch of child processes.
1111
const bench = common.createBenchmark(main, {
12-
len: [102400, 1024 * 1024 * 16],
12+
len: [102400, 1024 * 64 * 16],
1313
type: ['utf', 'asc', 'buf'],
1414
dur: [5],
1515
}, {

benchmark/net/tcp-raw-pipe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const util = require('util');
99
// run the function with those settings.
1010
// if not, then queue up a bunch of child processes.
1111
const bench = common.createBenchmark(main, {
12-
len: [102400, 1024 * 1024 * 16],
12+
len: [102400, 1024 * 64 * 16],
1313
type: ['utf', 'asc', 'buf'],
1414
dur: [5],
1515
}, {

benchmark/net/tcp-raw-s2c.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const util = require('util');
99
// run the function with those settings.
1010
// If not, then queue up a bunch of child processes.
1111
const bench = common.createBenchmark(main, {
12-
len: [102400, 1024 * 1024 * 16],
12+
len: [102400, 1024 * 64 * 16],
1313
type: ['utf', 'asc', 'buf'],
1414
dur: [5],
1515
}, {

doc/api/stream.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -3479,6 +3479,9 @@ method.
34793479

34803480
<!-- YAML
34813481
changes:
3482+
- version: REPLACEME
3483+
pr-url: https://github.com/nodejs/node/pull/52037
3484+
description: bump default highWaterMark.
34823485
- version: v15.5.0
34833486
pr-url: https://github.com/nodejs/node/pull/36431
34843487
description: support passing in an AbortSignal.
@@ -3500,7 +3503,7 @@ changes:
35003503
* `options` {Object}
35013504
* `highWaterMark` {number} Buffer level when
35023505
[`stream.write()`][stream-write] starts returning `false`. **Default:**
3503-
`16384` (16 KiB), or `16` for `objectMode` streams.
3506+
`65536` (64 KiB), or `16` for `objectMode` streams.
35043507
* `decodeStrings` {boolean} Whether to encode `string`s passed to
35053508
[`stream.write()`][stream-write] to `Buffer`s (with the encoding
35063509
specified in the [`stream.write()`][stream-write] call) before passing
@@ -3856,6 +3859,9 @@ constructor and implement the [`readable._read()`][] method.
38563859

38573860
<!-- YAML
38583861
changes:
3862+
- version: REPLACEME
3863+
pr-url: https://github.com/nodejs/node/pull/52037
3864+
description: bump default highWaterMark.
38593865
- version: v15.5.0
38603866
pr-url: https://github.com/nodejs/node/pull/36431
38613867
description: support passing in an AbortSignal.
@@ -3873,7 +3879,7 @@ changes:
38733879
* `options` {Object}
38743880
* `highWaterMark` {number} The maximum [number of bytes][hwm-gotcha] to store
38753881
in the internal buffer before ceasing to read from the underlying resource.
3876-
**Default:** `16384` (16 KiB), or `16` for `objectMode` streams.
3882+
**Default:** `65536` (64 KiB), or `16` for `objectMode` streams.
38773883
* `encoding` {string} If specified, then buffers will be decoded to
38783884
strings using the specified encoding. **Default:** `null`.
38793885
* `objectMode` {boolean} Whether this stream should behave

lib/internal/streams/state.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const { validateInteger } = require('internal/validators');
88

99
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
1010

11-
let defaultHighWaterMarkBytes = 16 * 1024;
11+
// TODO (fix): For some reason Windows CI fails with bigger hwm.
12+
let defaultHighWaterMarkBytes = process.platform === 'win32' ? 16 * 1024 : 64 * 1024;
1213
let defaultHighWaterMarkObjectMode = 16;
1314

1415
function highWaterMarkFrom(options, isDuplex, duplexKey) {

test/parallel/test-http-no-read-no-dump.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const server = http.createServer((req, res) => {
3434
}, common.mustCall((res) => {
3535
res.resume();
3636

37-
post.write(Buffer.alloc(16 * 1024).fill('X'));
37+
post.write(Buffer.alloc(64 * 1024).fill('X'));
3838
onPause = () => {
3939
post.end('something');
4040
};

test/parallel/test-https-hwm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ const httpsServer = https.createServer({
6262
port: this.address().port,
6363
rejectUnauthorized: false,
6464
highWaterMark: undefined,
65-
}, loadCallback(16 * 1024)).on('error', common.mustNotCall()).end();
65+
}, loadCallback(process.platform === 'win32' ? 16 * 1024 : 64 * 1024)).on('error', common.mustNotCall()).end();
6666
}));

test/parallel/test-stream-duplex-readable-end.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const stream = require('stream');
77
let loops = 5;
88

99
const src = new stream.Readable({
10+
highWaterMark: 16 * 1024,
1011
read() {
1112
if (loops--)
1213
this.push(Buffer.alloc(20000));
1314
}
1415
});
1516

1617
const dst = new stream.Transform({
18+
highWaterMark: 16 * 1024,
1719
transform(chunk, output, fn) {
1820
this.push(null);
1921
fn();

test/parallel/test-stream-pipe-await-drain-push-while-write.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const stream = require('stream');
44
const assert = require('assert');
55

66
const writable = new stream.Writable({
7+
highWaterMark: 16 * 1024,
78
write: common.mustCall(function(chunk, encoding, cb) {
89
assert.strictEqual(
910
readable._readableState.awaitDrainWriters,
@@ -26,6 +27,7 @@ const writable = new stream.Writable({
2627
// A readable stream which produces two buffers.
2728
const bufs = [Buffer.alloc(32 * 1024), Buffer.alloc(33 * 1024)]; // above hwm
2829
const readable = new stream.Readable({
30+
highWaterMark: 16 * 1024,
2931
read: function() {
3032
while (bufs.length > 0) {
3133
this.push(bufs.shift());

test/parallel/test-stream-readable-infinite-read.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { Readable } = require('stream');
77
const buf = Buffer.alloc(8192);
88

99
const readable = new Readable({
10+
highWaterMark: 16 * 1024,
1011
read: common.mustCall(function() {
1112
this.push(buf);
1213
}, 31)

test/parallel/test-stream-transform-split-highwatermark.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
require('../common');
33
const assert = require('assert');
44

5-
const { Transform, Readable, Writable } = require('stream');
5+
const { Transform, Readable, Writable, getDefaultHighWaterMark } = require('stream');
66

7-
const DEFAULT = 16 * 1024;
7+
const DEFAULT = getDefaultHighWaterMark();
88

99
function testTransform(expectedReadableHwm, expectedWritableHwm, options) {
1010
const t = new Transform(options);

test/parallel/test-stream-transform-split-objectmode.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ const assert = require('assert');
2525

2626
const Transform = require('stream').Transform;
2727

28-
const parser = new Transform({ readableObjectMode: true });
28+
const parser = new Transform({
29+
readableObjectMode: true
30+
});
2931

3032
assert(parser._readableState.objectMode);
3133
assert(!parser._writableState.objectMode);
3234
assert.strictEqual(parser.readableHighWaterMark, 16);
33-
assert.strictEqual(parser.writableHighWaterMark, 16 * 1024);
35+
assert.strictEqual(parser.writableHighWaterMark, process.platform === 'win32' ? 16 * 1024 : 64 * 1024);
3436
assert.strictEqual(parser.readableHighWaterMark,
3537
parser._readableState.highWaterMark);
3638
assert.strictEqual(parser.writableHighWaterMark,
@@ -57,7 +59,7 @@ const serializer = new Transform({ writableObjectMode: true });
5759

5860
assert(!serializer._readableState.objectMode);
5961
assert(serializer._writableState.objectMode);
60-
assert.strictEqual(serializer.readableHighWaterMark, 16 * 1024);
62+
assert.strictEqual(serializer.readableHighWaterMark, process.platform === 'win32' ? 16 * 1024 : 64 * 1024);
6163
assert.strictEqual(serializer.writableHighWaterMark, 16);
6264
assert.strictEqual(parser.readableHighWaterMark,
6365
parser._readableState.highWaterMark);

test/parallel/test-tls-connect-hwm-option.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ server.listen(0, common.mustCall(() => {
3737
rejectUnauthorized: false,
3838
highWaterMark: undefined,
3939
}, common.mustCall(() => {
40-
assert.strictEqual(defaultHighBob.readableHighWaterMark, 16 * 1024);
40+
assert.strictEqual(defaultHighBob.readableHighWaterMark, process.platform === 'win32' ? 16 * 1024 : 64 * 1024);
4141
defaultHighBob.end();
4242
}));
4343

test/parallel/test-zlib-brotli-16GB.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)