Skip to content

Commit

Permalink
Only send MAX_STREAMS when >1/8 of flow control window is consumed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith authored and djc committed Jun 17, 2024
1 parent 0e621df commit c7a2c40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@ impl Connection {
/// `count`s increase both minimum and worst-case memory consumption.
pub fn set_max_concurrent_streams(&mut self, dir: Dir, count: VarInt) {
self.streams.set_max_concurrent(dir, count);
// If the limit was reduced, then a flow control update previously deemed insignificant may
// now be significant.
let pending = &mut self.spaces[SpaceId::Data].pending;
self.streams.queue_max_stream_id(pending);
}

/// Current number of remotely initiated streams that may be concurrently open
Expand Down
19 changes: 15 additions & 4 deletions quinn-proto/src/connection/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,13 @@ impl StreamsState {
pub(crate) fn queue_max_stream_id(&mut self, pending: &mut Retransmits) -> bool {
let mut queued = false;
for dir in Dir::iter() {
let dirty = self.sent_max_remote[dir as usize] != self.max_remote[dir as usize];
pending.max_stream_id[dir as usize] |= dirty;
queued |= dirty;
let diff = self.max_remote[dir as usize] - self.sent_max_remote[dir as usize];
// To reduce traffic, only announce updates if at least 1/8 of the flow control window
// has been consumed.
if diff > self.max_concurrent_remote_count[dir as usize] / 8 {
pending.max_stream_id[dir as usize] = true;
queued = true;
}
}
queued
}
Expand Down Expand Up @@ -921,7 +925,14 @@ mod tests {

#[test]
fn trivial_flow_control() {
let mut client = make(Side::Client);
let mut client = StreamsState::new(
Side::Client,
1u32.into(),
1u32.into(),
1024 * 1024,
(1024 * 1024u32).into(),
(1024 * 1024u32).into(),
);
let id = StreamId::new(Side::Server, Dir::Uni, 0);
let initial_max = client.local_max_data;
const MESSAGE_SIZE: usize = 2048;
Expand Down

0 comments on commit c7a2c40

Please sign in to comment.