Skip to content

Commit

Permalink
proto: Allow GSO to be manually disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Aug 20, 2023
1 parent 5cca306 commit 22a5913
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct TransportConfig {
pub(crate) datagram_send_buffer_size: usize,

pub(crate) congestion_controller_factory: Box<dyn congestion::ControllerFactory + Send + Sync>,

pub(crate) enable_segmentation_offload: bool,
}

impl TransportConfig {
Expand Down Expand Up @@ -284,6 +286,21 @@ impl TransportConfig {
self.congestion_controller_factory = Box::new(factory);
self
}

/// Whether to use "Generic Segmentation Offload" to accelerate transmits, when supported by the
/// environment
///
/// Defaults to `true`.
///
/// GSO dramatically reduces CPU consumption when sending large numbers of packets with the same
/// headers, such as when transmitting bulk data on a connection. However, it is not supported
/// by all network interface drivers or packet inspection tools. `quinn-udp` will attempt to
/// disable GSO automatically when unavailable, but this can lead to spurious packet loss at
/// startup, temporarily degrading performance.
pub fn enable_segmentation_offload(&mut self, enabled: bool) -> &mut Self {
self.enable_segmentation_offload = enabled;
self
}
}

impl Default for TransportConfig {
Expand Down Expand Up @@ -319,6 +336,8 @@ impl Default for TransportConfig {
datagram_send_buffer_size: 1024 * 1024,

congestion_controller_factory: Box::new(Arc::new(congestion::CubicConfig::default())),

enable_segmentation_offload: true,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ impl Connection {
#[must_use]
pub fn poll_transmit(&mut self, now: Instant, max_datagrams: usize) -> Option<Transmit> {
assert!(max_datagrams != 0);
let max_datagrams = max_datagrams.min(MAX_TRANSMIT_SEGMENTS);
let max_datagrams = match self.config.enable_segmentation_offload {
false => 1,
true => max_datagrams.min(MAX_TRANSMIT_SEGMENTS),
};

let mut num_datagrams = 0;

Expand Down

0 comments on commit 22a5913

Please sign in to comment.