Skip to content

Commit 57a9469

Browse files
committed
Make HTTP/2 session and stream windows configurable
Issue #8199 outlines the issue. This PR adds a new setting to allow for setting the session window separately from the stream window. Closes #8199
1 parent a48f6cd commit 57a9469

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

doc/admin-guide/files/records.config.en.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,17 @@ HTTP/2 Configuration
41374137
:reloadable:
41384138
:units: bytes
41394139

4140-
The initial window size for inbound connections.
4140+
The initial window size for inbound connection streams.
4141+
4142+
.. ts:cv:: CONFIG proxy.config.http2.session_initial_window_size_in INT 0
4143+
:reloadable:
4144+
4145+
The initial window size for inbound connection session. HTTP/2 provides both
4146+
a per stream window and a session wide window. Each data byte exchanged decrements
4147+
the window of the associated stream and the session window. To allow for multiple
4148+
active streams, the session window should be larger than the stream window.
4149+
|TS| verifies that the session initial window is always at least as large as the
4150+
stream initial window.
41414151

41424152
.. ts:cv:: CONFIG proxy.config.http2.max_frame_size INT 16384
41434153
:reloadable:

mgmt/RecordsConfig.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,8 @@ static const RecordElement RecordsConfig[] =
12991299
,
13001300
{RECT_CONFIG, "proxy.config.http2.initial_window_size_in", RECD_INT, "65535", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[0-9]+$", RECA_NULL}
13011301
,
1302+
{RECT_CONFIG, "proxy.config.http2.session_initial_window_size_in", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[0-9]+$", RECA_NULL}
1303+
,
13021304
{RECT_CONFIG, "proxy.config.http2.max_frame_size", RECD_INT, "16384", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[0-9]+$", RECA_NULL}
13031305
,
13041306
{RECT_CONFIG, "proxy.config.http2.header_table_size", RECD_INT, "4096", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[0-9]+$", RECA_NULL}

proxy/http2/HTTP2.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ uint32_t Http2::max_active_streams_in = 0;
571571
bool Http2::throttling = false;
572572
uint32_t Http2::stream_priority_enabled = 0;
573573
uint32_t Http2::initial_window_size = 65535;
574+
uint32_t Http2::session_initial_window_size = 65535;
574575
uint32_t Http2::max_frame_size = 16384;
575576
uint32_t Http2::header_table_size = 4096;
576577
uint32_t Http2::max_header_list_size = 4294967295;
@@ -603,6 +604,13 @@ Http2::init()
603604
REC_EstablishStaticConfigInt32U(max_active_streams_in, "proxy.config.http2.max_active_streams_in");
604605
REC_EstablishStaticConfigInt32U(stream_priority_enabled, "proxy.config.http2.stream_priority_enabled");
605606
REC_EstablishStaticConfigInt32U(initial_window_size, "proxy.config.http2.initial_window_size_in");
607+
REC_EstablishStaticConfigInt32U(session_initial_window_size, "proxy.config.http2.session_initial_window_size_in");
608+
609+
// The session window must be at least as big as the stream window
610+
if (session_initial_window_size < initial_window_size) {
611+
session_initial_window_size = initial_window_size;
612+
}
613+
606614
REC_EstablishStaticConfigInt32U(max_frame_size, "proxy.config.http2.max_frame_size");
607615
REC_EstablishStaticConfigInt32U(header_table_size, "proxy.config.http2.header_table_size");
608616
REC_EstablishStaticConfigInt32U(max_header_list_size, "proxy.config.http2.max_header_list_size");

proxy/http2/HTTP2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ class Http2
374374
static bool throttling;
375375
static uint32_t stream_priority_enabled;
376376
static uint32_t initial_window_size;
377+
static uint32_t session_initial_window_size;
377378
static uint32_t max_frame_size;
378379
static uint32_t header_table_size;
379380
static uint32_t max_header_list_size;

proxy/http2/Http2ConnectionState.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ void
10401040
Http2ConnectionState::init(Http2CommonSession *ssn)
10411041
{
10421042
session = ssn;
1043-
this->_server_rwnd = Http2::initial_window_size;
1043+
this->_server_rwnd = Http2::session_initial_window_size;
10441044

10451045
local_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE);
10461046
remote_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE);
@@ -1073,8 +1073,10 @@ Http2ConnectionState::send_connection_preface()
10731073

10741074
send_settings_frame(configured_settings);
10751075

1076-
if (server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) > HTTP2_INITIAL_WINDOW_SIZE) {
1077-
send_window_update_frame(0, server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - HTTP2_INITIAL_WINDOW_SIZE);
1076+
// If the session window size is non-default, send a window update right away
1077+
1078+
if (Http2::session_initial_window_size > HTTP2_INITIAL_WINDOW_SIZE) {
1079+
send_window_update_frame(0, Http2::session_initial_window_size - HTTP2_INITIAL_WINDOW_SIZE);
10781080
}
10791081
}
10801082

@@ -1417,7 +1419,7 @@ Http2ConnectionState::restart_streams()
14171419
void
14181420
Http2ConnectionState::restart_receiving(Http2Stream *stream)
14191421
{
1420-
uint32_t initial_rwnd = this->server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE);
1422+
uint32_t initial_rwnd = Http2::session_initial_window_size;
14211423
uint32_t min_rwnd = std::min(initial_rwnd, this->server_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE));
14221424

14231425
// Connection level WINDOW UPDATE
@@ -1438,6 +1440,8 @@ Http2ConnectionState::restart_receiving(Http2Stream *stream)
14381440
return;
14391441
}
14401442

1443+
// Update the window size for the stream
1444+
initial_rwnd = Http2::initial_window_size;
14411445
Http2WindowSize diff_size = initial_rwnd - std::max(static_cast<int64_t>(stream->server_rwnd()), data_size);
14421446
stream->increment_server_rwnd(diff_size);
14431447
this->send_window_update_frame(stream->get_id(), diff_size);

0 commit comments

Comments
 (0)