diff --git a/quinn-proto/src/config.rs b/quinn-proto/src/config.rs index 165713ae2..57cac79d7 100644 --- a/quinn-proto/src/config.rs +++ b/quinn-proto/src/config.rs @@ -49,6 +49,8 @@ pub struct TransportConfig { pub(crate) datagram_send_buffer_size: usize, pub(crate) congestion_controller_factory: Box, + + pub(crate) enable_segmentation_offload: bool, } impl TransportConfig { @@ -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 { @@ -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, } } } diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 63096dd29..d118e2822 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -449,7 +449,10 @@ impl Connection { #[must_use] pub fn poll_transmit(&mut self, now: Instant, max_datagrams: usize) -> Option { 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;