GeezerVison is showing github.com — http2: increase default window sizes · nodejs/node@1576cb8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/http2.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3656,7 +3656,7 @@ properties. | 3656 | 3656 | permitted on the `Http2Session` instances. **Default:** `true`. | 3657 | 3657 | * `initialWindowSize` {number} Specifies the _sender's_ initial window size in | 3658 | 3658 | bytes for stream-level flow control. The minimum allowed value is 0. The | 3659 | | - maximum allowed value is 2<sup>32</sup>-1. **Default:** `65535`. | | 3659 | + maximum allowed value is 2<sup>32</sup>-1. **Default:** `4194304`. | 3660 | 3660 | * `maxFrameSize` {number} Specifies the size in bytes of the largest frame | 3661 | 3661 | payload. The minimum allowed value is 16,384. The maximum allowed value is | 3662 | 3662 | 2<sup>24</sup>-1. **Default:** `16384`. | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1205,7 +1205,16 @@ function setupHandle(socket, type, options) { | 1205 | 1205 | } | 1206 | 1206 |
| 1207 | 1207 | const settings = typeof options.settings === 'object' ? | 1208 | | - options.settings : {}; | | 1208 | + { ...options.settings } : {}; | | 1209 | + | | 1210 | + // Increase the default initial window size to improve throughput | | 1211 | + // on high-latency connections. The HTTP/2 default of 65535 (64KB) | | 1212 | + // limits throughput to window_size / RTT. By increasing to 4MB, | | 1213 | + // throughput is significantly improved. | | 1214 | + // See https://github.com/nodejs/node/issues/38426 | | 1215 | + if (settings.initialWindowSize === undefined) { | | 1216 | + settings.initialWindowSize = constants.DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE; | | 1217 | + } | 1209 | 1218 |
| 1210 | 1219 | this.settings(settings); | 1211 | 1220 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_http2.cc +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -612,6 +612,17 @@ Http2Session::Http2Session(Http2State* http2_state, | 612 | 612 | &alloc_info), 0); | 613 | 613 | session_.reset(session); | 614 | 614 |
| | 615 | + // Increase the default local connection window to improve throughput | | 616 | + // on high-latency connections. The default 64KB window limits throughput | | 617 | + // to window_size / RTT. With a 32MB connection window, throughput is | | 618 | + // significantly improved. See https://github.com/nodejs/node/issues/38426 | | 619 | + CHECK_EQ(nghttp2_session_set_local_window_size( | | 620 | + session, | | 621 | + NGHTTP2_FLAG_NONE, | | 622 | + 0, | | 623 | + DEFAULT_SETTINGS_LOCAL_CONNECTION_WINDOW_SIZE), | | 624 | + 0); | | 625 | + | 615 | 626 | outgoing_storage_.reserve(1024); | 616 | 627 | outgoing_buffers_.reserve(32); | 617 | 628 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_http2.h +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,14 +43,18 @@ constexpr uint64_t kDefaultMaxSessionMemory = 10000000; | 43 | 43 | constexpr uint32_t DEFAULT_SETTINGS_HEADER_TABLE_SIZE = 4096; | 44 | 44 | constexpr uint32_t DEFAULT_SETTINGS_ENABLE_PUSH = 1; | 45 | 45 | constexpr uint32_t DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS = 0xffffffffu; | 46 | | -constexpr uint32_t DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE = 65535; | | 46 | +constexpr uint32_t DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE = 4194304; | 47 | 47 | constexpr uint32_t DEFAULT_SETTINGS_MAX_FRAME_SIZE = 16384; | 48 | 48 | constexpr uint32_t DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE = 65535; | 49 | 49 | constexpr uint32_t DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0; | 50 | 50 | constexpr uint32_t MAX_MAX_FRAME_SIZE = 16777215; | 51 | 51 | constexpr uint32_t MIN_MAX_FRAME_SIZE = DEFAULT_SETTINGS_MAX_FRAME_SIZE; | 52 | 52 | constexpr uint32_t MAX_INITIAL_WINDOW_SIZE = 2147483647; | 53 | 53 |
| | 54 | +// Default local connection window size (32MB) to improve throughput | | 55 | +// on high-latency connections. See https://github.com/nodejs/node/issues/38426 | | 56 | +constexpr uint32_t DEFAULT_SETTINGS_LOCAL_CONNECTION_WINDOW_SIZE = 33554432; | | 57 | + | 54 | 58 | // Stream is not going to have any DATA frames | 55 | 59 | constexpr int STREAM_OPTION_EMPTY_PAYLOAD = 0x1; | 56 | 60 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/stream_base.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -752,6 +752,8 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { | 752 | 752 | void ReportWritesToJSStreamListener::OnStreamAfterReqFinished( | 753 | 753 | StreamReq* req_wrap, int status) { | 754 | 754 | StreamBase* stream = static_cast<StreamBase*>(stream_); | | 755 | + if (stream == nullptr) return; | | 756 | + if (req_wrap == nullptr) return; | 755 | 757 | Environment* env = stream->stream_env(); | 756 | 758 | if (!env->can_call_into_js()) return; | 757 | 759 | AsyncWrap* async_wrap = req_wrap->GetAsyncWrap(); | |
Collapse file Copy file name to clipboardExpand all lines: src/stream_pipe.cc +11-4Lines changed: 11 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,7 @@ void StreamPipe::Unpipe(bool is_in_deletion) { | 59 | 59 | is_closed_ = true; | 60 | 60 | is_reading_ = false; | 61 | 61 | source()->RemoveStreamListener(&readable_listener_); | 62 | | - if (pending_writes_ == 0) | | 62 | + if (pending_writes_ == 0 || sink_destroyed_) | 63 | 63 | sink()->RemoveStreamListener(&writable_listener_); | 64 | 64 |
| 65 | 65 | if (is_in_deletion) return; | @@ -159,13 +159,18 @@ void StreamPipe::WritableListener::OnStreamAfterWrite(WriteWrap* w, | 159 | 159 | StreamPipe* pipe = ContainerOf(&StreamPipe::writable_listener_, this); | 160 | 160 | pipe->pending_writes_--; | 161 | 161 | if (pipe->is_closed_) { | 162 | | - if (pipe->pending_writes_ == 0) { | | 162 | + // If the sink has been destroyed, pending_writes_ may have been | | 163 | + // reset and we should check <= 0 instead of == 0. Also guard | | 164 | + // against the listener having already been removed. | | 165 | + bool writes_done = pipe->sink_destroyed_ ? pipe->pending_writes_ <= 0 | | 166 | + : pipe->pending_writes_ == 0; | | 167 | + if (writes_done) { | 163 | 168 | Environment* env = pipe->env(); | 164 | 169 | HandleScope handle_scope(env->isolate()); | 165 | 170 | Context::Scope context_scope(env->context()); | 166 | 171 | if (pipe->MakeCallback(env->oncomplete_string(), 0, nullptr).IsEmpty()) | 167 | 172 | return; | 168 | | - stream()->RemoveStreamListener(this); | | 173 | + if (stream() != nullptr) stream()->RemoveStreamListener(this); | 169 | 174 | } | 170 | 175 | return; | 171 | 176 | } | @@ -213,7 +218,9 @@ void StreamPipe::WritableListener::OnStreamDestroy() { | 213 | 218 | StreamPipe* pipe = ContainerOf(&StreamPipe::writable_listener_, this); | 214 | 219 | pipe->sink_destroyed_ = true; | 215 | 220 | pipe->is_eof_ = true; | 216 | | - pipe->pending_writes_ = 0; | | 221 | + // Don't reset pending_writes_ here; let OnStreamAfterWrite track | | 222 | + // completion naturally. Unpipe() will remove this listener from the | | 223 | + // sink regardless of pending_writes_ since sink_destroyed_ is set. | 217 | 224 | pipe->Unpipe(); | 218 | 225 | } | 219 | 226 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-binding.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ const settings = http2.getDefaultSettings(); | 17 | 17 | assert.strictEqual(settings.headerTableSize, 4096); | 18 | 18 | assert.strictEqual(settings.enablePush, true); | 19 | 19 | assert.strictEqual(settings.maxConcurrentStreams, 4294967295); | 20 | | -assert.strictEqual(settings.initialWindowSize, 65535); | | 20 | +assert.strictEqual(settings.initialWindowSize, 4194304); | 21 | 21 | assert.strictEqual(settings.maxFrameSize, 16384); | 22 | 22 |
| 23 | 23 | assert.strictEqual(binding.nghttp2ErrorString(-517), | @@ -239,7 +239,7 @@ const defaultSettings = { | 239 | 239 | DEFAULT_SETTINGS_HEADER_TABLE_SIZE: 4096, | 240 | 240 | DEFAULT_SETTINGS_ENABLE_PUSH: 1, | 241 | 241 | DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 4294967295, | 242 | | - DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 65535, | | 242 | + DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 4194304, | 243 | 243 | DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384, | 244 | 244 | DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: 65535, | 245 | 245 | DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL: 0 | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-client-setLocalWindowSize.js +14-15Lines changed: 14 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,15 +73,16 @@ const http2 = require('http2'); | 73 | 73 |
| 74 | 74 | client.on('connect', common.mustCall(() => { | 75 | 75 | const windowSize = 2 ** 20; | 76 | | - const defaultSetting = http2.getDefaultSettings(); | 77 | 76 | client.setLocalWindowSize(windowSize); | 78 | 77 |
| 79 | 78 | assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize); | 80 | | - assert.strictEqual(client.state.localWindowSize, windowSize); | 81 | | - assert.strictEqual( | 82 | | - client.state.remoteWindowSize, | 83 | | - defaultSetting.initialWindowSize | 84 | | - ); | | 79 | + // localWindowSize returns the available connection window. | | 80 | + // When decreasing from the default 33554432 to 1048576, | | 81 | + // the available window stays at 33554432. | | 82 | + assert.strictEqual(client.state.localWindowSize, 33554432); | | 83 | + // remoteWindowSize is the connection-level send window, | | 84 | + // which remains at the HTTP/2 default of 65535. | | 85 | + assert.strictEqual(client.state.remoteWindowSize, 65535); | 85 | 86 |
| 86 | 87 | server.close(); | 87 | 88 | client.close(); | @@ -101,18 +102,16 @@ const http2 = require('http2'); | 101 | 102 |
| 102 | 103 | client.on('connect', common.mustCall(() => { | 103 | 104 | const windowSize = 20; | 104 | | - const defaultSetting = http2.getDefaultSettings(); | 105 | 105 | client.setLocalWindowSize(windowSize); | 106 | 106 |
| 107 | 107 | assert.strictEqual(client.state.effectiveLocalWindowSize, windowSize); | 108 | | - assert.strictEqual( | 109 | | - client.state.localWindowSize, | 110 | | - defaultSetting.initialWindowSize | 111 | | - ); | 112 | | - assert.strictEqual( | 113 | | - client.state.remoteWindowSize, | 114 | | - defaultSetting.initialWindowSize | 115 | | - ); | | 108 | + // localWindowSize returns the available connection window. | | 109 | + // When decreasing from the default 33554432 to 20, | | 110 | + // the available window stays at 33554432. | | 111 | + assert.strictEqual(client.state.localWindowSize, 33554432); | | 112 | + // remoteWindowSize is the connection-level send window, | | 113 | + // which remains at the HTTP/2 default of 65535. | | 114 | + assert.strictEqual(client.state.remoteWindowSize, 65535); | 116 | 115 |
| 117 | 116 | server.close(); | 118 | 117 | client.close(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-getpackedsettings.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ const http2 = require('http2'); | 9 | 9 | const check = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x10, 0x00, | 10 | 10 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, | 11 | 11 | 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, | 12 | | - 0x00, 0x04, 0x00, 0x00, 0xff, 0xff, | | 12 | + 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, | 13 | 13 | 0x00, 0x05, 0x00, 0x00, 0x40, 0x00, | 14 | 14 | 0x00, 0x06, 0x00, 0x00, 0xff, 0xff, | 15 | 15 | 0x00, 0x08, 0x00, 0x00, 0x00, 0x00]); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-pack-end-stream-flag.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,8 +52,10 @@ function testRequest(path, targetFrameCount, callback) { | 52 | 52 | }); | 53 | 53 | } | 54 | 54 |
| 55 | | -// SETTINGS => SETTINGS => HEADERS => DATA | 56 | | -const MIN_FRAME_COUNT = 4; | | 55 | +// SETTINGS => WINDOW_UPDATE => SETTINGS ACK => HEADERS => DATA | | 56 | +// The WINDOW_UPDATE frame is sent because the default local connection | | 57 | +// window is now increased to 32MB (see https://github.com/nodejs/node/issues/38426) | | 58 | +const MIN_FRAME_COUNT = 5; | 57 | 59 |
| 58 | 60 | server.listen(0, () => { | 59 | 61 | testRequest('/singleEnd', MIN_FRAME_COUNT, () => { | |
|