Skip to content

Commit 45320c0

Browse files
committed
streamer: scale max_concurrent_uni_streams with BDP
1 parent 947617c commit 45320c0

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

streamer/src/nonblocking/swqos.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub const QUIC_MAX_STAKED_CONCURRENT_STREAMS: usize = 512;
4949

5050
pub const QUIC_TOTAL_STAKED_CONCURRENT_STREAMS: usize = 100_000;
5151

52+
/// RTT after which we start BDP scaling
53+
const REFERENCE_RTT_MS: u64 = 50;
54+
55+
/// Above this RTT we stop scaling for BDP
56+
const MAX_RTT_MS: u64 = 350;
57+
5258
#[derive(Clone)]
5359
pub struct SwQosConfig {
5460
pub max_streams_per_ms: u64,
@@ -140,8 +146,12 @@ impl SwQos {
140146
}
141147
}
142148

143-
fn compute_max_allowed_uni_streams(peer_type: ConnectionPeerType, total_stake: u64) -> usize {
144-
match peer_type {
149+
fn compute_max_allowed_uni_streams_with_rtt(
150+
rtt_millis: u64,
151+
peer_type: ConnectionPeerType,
152+
total_stake: u64,
153+
) -> usize {
154+
let streams = match peer_type {
145155
ConnectionPeerType::Staked(peer_stake) => {
146156
// No checked math for f64 type. So let's explicitly check for 0 here
147157
if total_stake == 0 || peer_stake > total_stake {
@@ -164,7 +174,10 @@ fn compute_max_allowed_uni_streams(peer_type: ConnectionPeerType, total_stake: u
164174
}
165175
}
166176
ConnectionPeerType::Unstaked => QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS,
167-
}
177+
};
178+
// scale amount of streams based on RTT if RTT is larger than REFERENCE_RTT_MS
179+
// multiply first then divide to avoid rounding errors.
180+
(streams * rtt_millis.clamp(REFERENCE_RTT_MS, MAX_RTT_MS) as usize) / REFERENCE_RTT_MS as usize
168181
}
169182

170183
impl SwQos {
@@ -182,7 +195,10 @@ impl SwQos {
182195
),
183196
ConnectionHandlerError,
184197
> {
185-
if let Ok(max_uni_streams) = VarInt::from_u64(compute_max_allowed_uni_streams(
198+
// get current RTT and limit it to MAX_RTT_MS
199+
let rtt_millis = connection.rtt().as_millis() as u64;
200+
if let Ok(max_uni_streams) = VarInt::from_u64(compute_max_allowed_uni_streams_with_rtt(
201+
rtt_millis,
186202
conn_context.peer_type(),
187203
conn_context.total_stake,
188204
) as u64)
@@ -525,6 +541,10 @@ impl QosController<SwQosConnectionContext> for SwQos {
525541
pub mod test {
526542
use super::*;
527543

544+
fn compute_max_allowed_uni_streams(peer_type: ConnectionPeerType, total_stake: u64) -> usize {
545+
compute_max_allowed_uni_streams_with_rtt(REFERENCE_RTT_MS, peer_type, total_stake)
546+
}
547+
528548
#[test]
529549
fn test_max_allowed_uni_streams() {
530550
assert_eq!(

0 commit comments

Comments
 (0)