Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters for stream concurrency metrics and related documentation #1518

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,15 @@ impl Connection {
self.streams.set_max_concurrent(dir, count);
}

/// Current number of remotely initiated streams that may be concurrently open
///
/// If the target for this limit is reduced using [`set_max_concurrent_streams`](Self::set_max_concurrent_streams),
/// it will not change immediately, even if fewer streams are open. Instead, it will
/// decrement by one for each time a remotely initiated stream of matching directionality is closed.
pub fn max_concurrent_streams(&self, dir: Dir) -> u64 {
self.streams.max_concurrent(dir)
}

/// See [`TransportConfig::receive_window()`]
pub fn set_receive_window(&mut self, receive_window: VarInt) {
if self.streams.set_receive_window(receive_window) {
Expand Down
13 changes: 13 additions & 0 deletions quinn-proto/src/connection/streams/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<'a> Streams<'a> {
/// Accept a remotely initiated stream of a certain directionality, if possible
///
/// Returns `None` if there are no new incoming streams for this connection.
/// Has no impact on the data flow-control or stream concurrency limits.
pub fn accept(&mut self, dir: Dir) -> Option<StreamId> {
if self.state.next_remote[dir as usize] == self.state.next_reported_remote[dir as usize] {
return None;
Expand All @@ -79,6 +80,18 @@ impl<'a> Streams<'a> {
pub fn send_streams(&self) -> usize {
self.state.send_streams
}

/// The number of remotely initiated open streams of a certain directionality.
///
/// Includes remotely initiated streams, which have not been accepted via [`accept`](Self::accept).
/// These streams count against the respective concurrency limit reported by
/// [`Connection::max_concurrent_streams`](super::Connection::max_concurrent_streams).
pub fn remote_open_streams(&self, dir: Dir) -> u64 {
Ralith marked this conversation as resolved.
Show resolved Hide resolved
// total opened - total closed = total opened - ( total permitted - total permitted unclosed )
self.state.next_remote[dir as usize]
- (self.state.max_remote[dir as usize]
- self.state.allocated_remote_count[dir as usize])
Ralith marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Access to streams
Expand Down
8 changes: 6 additions & 2 deletions quinn-proto/src/connection/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub struct StreamsState {
pub(super) max: [u64; 2],
/// Maximum number of remotely-initiated streams that may be opened over the lifetime of the
/// connection so far, per direction
max_remote: [u64; 2],
pub(super) max_remote: [u64; 2],
/// Number of streams that we've given the peer permission to open and which aren't fully closed
allocated_remote_count: [u64; 2],
pub(super) allocated_remote_count: [u64; 2],
Ralith marked this conversation as resolved.
Show resolved Hide resolved
/// Size of the desired stream flow control window. May be smaller than `allocated_remote_count`
/// due to `set_max_concurrent` calls.
max_concurrent_remote_count: [u64; 2],
Expand Down Expand Up @@ -763,6 +763,10 @@ impl StreamsState {
self.ensure_remote_streams(dir);
}

pub fn max_concurrent(&self, dir: Dir) -> u64 {
self.allocated_remote_count[dir as usize]
}

/// Set the receive_window and returns wether the receive_window has been
/// expanded or shrunk: true if expanded, false if shrunk.
pub fn set_receive_window(&mut self, receive_window: VarInt) -> bool {
Expand Down