Skip to content

Commit a99a8b0

Browse files
authored
QUIC: Add memory_reduction_timeout configuration (#44408)
Commit Message: quic: add memory_reduction_timeout configuration support Additional Description: Added a new configuration option `memory_reduction_timeout` to `QuicProtocolOptions` to allow setting a timeout for memory reduction callbacks when the network is idle. Risk Level: low Testing: N/A Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] --------- Signed-off-by: Ting Pan <panting@google.com>
1 parent 7f73dbc commit a99a8b0

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

api/envoy/config/core/v3/protocol.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ message QuicKeepAliveSettings {
5757
}
5858

5959
// QUIC protocol options which apply to both downstream and upstream connections.
60-
// [#next-free-field: 12]
60+
// [#next-free-field: 13]
6161
message QuicProtocolOptions {
6262
// Config for QUIC connection migration across network interfaces, i.e. cellular to WIFI, upon
6363
// network change events from the platform, i.e. the current network gets
@@ -173,6 +173,12 @@ message QuicProtocolOptions {
173173
// If absent, the feature will be disabled.
174174
// [#not-implemented-hide:]
175175
ConnectionMigrationSettings connection_migration = 11;
176+
177+
// Timeout for a QUIC connection to schedule memory reduction callback when the network has been idle for a while.
178+
// This value should be smaller than the idle timeout to take effect.
179+
// If not specified, memory reduction is set to infinite by QUIC connection (disabled).
180+
google.protobuf.Duration memory_reduction_timeout = 12
181+
[(validate.rules).duration = {gte {seconds: 1}}];
176182
}
177183

178184
message UpstreamHttpProtocolOptions {

source/common/quic/envoy_quic_server_session.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ void EnvoyQuicServerSession::setHttp3Options(
214214
}
215215
}
216216
}
217+
if (http3_options.has_quic_protocol_options()) {
218+
const uint64_t memory_reduction_timeout_ms = PROTOBUF_GET_MS_OR_DEFAULT(
219+
http3_options.quic_protocol_options(), memory_reduction_timeout, 0);
220+
if (memory_reduction_timeout_ms > 0) {
221+
connection()->SetMemoryReductionTimeout(
222+
quic::QuicTime::Delta::FromMilliseconds(memory_reduction_timeout_ms));
223+
}
224+
}
217225
set_allow_extended_connect(http3_options_->allow_extended_connect());
218226
if (http3_options_->disable_qpack()) {
219227
DisableHuffmanEncoding();

test/common/quic/envoy_quic_server_session_test.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,32 @@ TEST_F(EnvoyQuicServerSessionTest, SessionIdleCallbacksIdempotency) {
13461346
EXPECT_CALL(session_idle_list_, RemoveSession(_));
13471347
}
13481348

1349+
TEST_F(EnvoyQuicServerSessionTest, MemoryReductionTimeoutTest) {
1350+
envoy::config::core::v3::Http3ProtocolOptions http3_options;
1351+
auto* quic_options = http3_options.mutable_quic_protocol_options();
1352+
quic_options->mutable_memory_reduction_timeout()->set_seconds(300);
1353+
1354+
// Mark handshake complete and set connection idle timeout to a large duration.
1355+
quic::test::QuicConnectionPeer::GetIdleNetworkDetector(quic_connection_)
1356+
.SetTimeouts(quic::QuicTime::Delta::Infinite(), quic::QuicTime::Delta::FromSeconds(600));
1357+
1358+
envoy_quic_session_.setHttp3Options(http3_options);
1359+
1360+
// Trigger SetAlarm.
1361+
quic::test::QuicConnectionPeer::GetIdleNetworkDetector(quic_connection_)
1362+
.OnPacketReceived(connection_helper_.GetClock()->Now());
1363+
1364+
// Check the alarm deadline.
1365+
quic::QuicAlarmProxy idle_detector_alarm =
1366+
quic::test::QuicConnectionPeer::GetIdleNetworkDetectorAlarm(quic_connection_);
1367+
1368+
EXPECT_TRUE(idle_detector_alarm.IsSet());
1369+
EXPECT_EQ(connection_helper_.GetClock()->Now() + quic::QuicTime::Delta::FromSeconds(300),
1370+
idle_detector_alarm.deadline());
1371+
1372+
installReadFilter();
1373+
}
1374+
13491375
class EnvoyQuicServerSessionTestWillNotInitialize : public EnvoyQuicServerSessionTest {
13501376
void SetUp() override {}
13511377
void TearDown() override {

0 commit comments

Comments
 (0)