proto: Allow GSO to be manually disabled

This commit is contained in:
Benjamin Saunders
2023-08-20 11:53:42 -07:00
parent 5cca3063f6
commit a06838abde
2 changed files with 23 additions and 1 deletions
+19
View File
@@ -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 {
@@ -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,
}
}
}
+4 -1
View File
@@ -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;