Skip to content

Commit 0c4a13c

Browse files
committed
streamer: scale max_concurrent_uni_streams with BDP
1 parent 947617c commit 0c4a13c

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

streamer/src/nonblocking/swqos.rs

Lines changed: 31 additions & 8 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(
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,9 @@ 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+
let streams = streams * rtt_millis.clamp(REFERENCE_RTT_MS, MAX_RTT_MS) / REFERENCE_RTT_MS;
179+
streams as usize
168180
}
169181

170182
impl SwQos {
@@ -182,7 +194,10 @@ impl SwQos {
182194
),
183195
ConnectionHandlerError,
184196
> {
197+
// get current RTT and limit it to MAX_RTT_MS
198+
let rtt_millis = connection.rtt().as_millis() as u64;
185199
if let Ok(max_uni_streams) = VarInt::from_u64(compute_max_allowed_uni_streams(
200+
rtt_millis,
186201
conn_context.peer_type(),
187202
conn_context.total_stake,
188203
) as u64)
@@ -528,26 +543,34 @@ pub mod test {
528543
#[test]
529544
fn test_max_allowed_uni_streams() {
530545
assert_eq!(
531-
compute_max_allowed_uni_streams(ConnectionPeerType::Unstaked, 0),
546+
compute_max_allowed_uni_streams(REFERENCE_RTT_MS, ConnectionPeerType::Unstaked, 0),
532547
QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS
533548
);
534549
assert_eq!(
535-
compute_max_allowed_uni_streams(ConnectionPeerType::Staked(10), 0),
550+
compute_max_allowed_uni_streams(REFERENCE_RTT_MS, ConnectionPeerType::Staked(10), 0),
536551
QUIC_MIN_STAKED_CONCURRENT_STREAMS
537552
);
538553
let delta =
539554
(QUIC_TOTAL_STAKED_CONCURRENT_STREAMS - QUIC_MIN_STAKED_CONCURRENT_STREAMS) as f64;
540555
assert_eq!(
541-
compute_max_allowed_uni_streams(ConnectionPeerType::Staked(1000), 10000),
556+
compute_max_allowed_uni_streams(
557+
REFERENCE_RTT_MS,
558+
ConnectionPeerType::Staked(1000),
559+
10000
560+
),
542561
QUIC_MAX_STAKED_CONCURRENT_STREAMS,
543562
);
544563
assert_eq!(
545-
compute_max_allowed_uni_streams(ConnectionPeerType::Staked(100), 10000),
564+
compute_max_allowed_uni_streams(
565+
REFERENCE_RTT_MS,
566+
ConnectionPeerType::Staked(100),
567+
10000
568+
),
546569
((delta / (100_f64)) as usize + QUIC_MIN_STAKED_CONCURRENT_STREAMS)
547570
.min(QUIC_MAX_STAKED_CONCURRENT_STREAMS)
548571
);
549572
assert_eq!(
550-
compute_max_allowed_uni_streams(ConnectionPeerType::Unstaked, 10000),
573+
compute_max_allowed_uni_streams(REFERENCE_RTT_MS, ConnectionPeerType::Unstaked, 10000),
551574
QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS
552575
);
553576
}

0 commit comments

Comments
 (0)