From b5ca078bae939a6968df2d3e35f1d5d009d8062f Mon Sep 17 00:00:00 2001 From: Oussama Teffahi <70609372+oteffahi@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:09:01 +0100 Subject: [PATCH] Update TCP buffer size config (#1648) * Rename TCP buffer size parameters, duplicate config for TLS and TCP * Update tcp buffer size tests * Update DEFAULT_CONFIG, add more examples * Update DEFAULT_CONFIG --- DEFAULT_CONFIG.json5 | 27 +++++++++++++++++----- commons/zenoh-config/src/lib.rs | 15 ++++++++---- io/zenoh-link-commons/src/lib.rs | 4 ++-- io/zenoh-links/zenoh-link-tcp/src/utils.rs | 17 +++++++------- io/zenoh-links/zenoh-link-tls/src/utils.rs | 19 ++++++++------- zenoh/tests/tcp_buffers.rs | 18 +++++++-------- 6 files changed, 60 insertions(+), 40 deletions(-) diff --git a/DEFAULT_CONFIG.json5 b/DEFAULT_CONFIG.json5 index 6b3e5ee7b..552107328 100644 --- a/DEFAULT_CONFIG.json5 +++ b/DEFAULT_CONFIG.json5 @@ -25,6 +25,9 @@ /// /// It is also possible to specify a priority range and/or a reliability setting to be used on the link. /// For example `tcp/localhost?prio=6-7;rel=0` assigns priorities "data_low" and "background" to the established link. + /// + /// For TCP and TLS links, it is possible to specify the TCP buffer sizes: + /// E.g. tcp/192.168.0.1:7447#so_sndbuf=65000;so_rcvbuf=65000 connect: { /// timeout waiting for all endpoints connected (0: no retry, -1: infinite timeout) /// Accepts a single value (e.g. timeout_ms: 0) @@ -68,6 +71,9 @@ /// /// It is also possible to specify a priority range and/or a reliability setting to be used on the link. /// For example `tcp/localhost?prio=6-7;rel=0` assigns priorities "data_low" and "background" to the established link. + /// + /// For TCP and TLS links, it is possible to specify the TCP buffer sizes: + /// E.g. tcp/192.168.0.1:7447#so_sndbuf=65000;so_rcvbuf=65000 listen: { /// timeout waiting for all listen endpoints (0: no retry, -1: infinite timeout) /// Accepts a single value (e.g. timeout_ms: 0) @@ -494,13 +500,22 @@ // If set to true, links that require certificates (tls/quic) will automatically disconnect when the time of expiration of the remote certificate chain is reached // note that mTLS (client authentication) is required for a listener to disconnect a client on expiration close_link_on_expiration: false, + /// Optional configuration for TCP system buffers sizes for TLS links + /// + /// Configure TCP read buffer size (bytes) + // so_rcvbuf: 123456, + /// Configure TCP write buffer size (bytes) + // so_sndbuf: 123456, }, - /// Optional configuration for TCP system buffers sizes. Applies to TCP and TLS links. - /// - /// Configure TCP read buffer size (bytes) - // tcp_rx_buffer: 123456, - /// Configure TCP write buffer size (bytes) - // tcp_tx_buffer: 123456, + // // Configure optional TCP link specific parameters + // tcp: { + // /// Optional configuration for TCP system buffers sizes for TCP links + // /// + // /// Configure TCP read buffer size (bytes) + // // so_rcvbuf: 123456, + // /// Configure TCP write buffer size (bytes) + // // so_sndbuf: 123456, + // } }, /// Shared memory configuration. /// NOTE: shared memory can be used only if zenoh is compiled with "shared-memory" feature, otherwise diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index f0ba50d0a..8ab4d5d3a 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -499,6 +499,10 @@ validated_struct::validator! { connect_certificate: Option, verify_name_on_connect: Option, close_link_on_expiration: Option, + /// Configure TCP write buffer size + pub so_sndbuf: Option, + /// Configure TCP read buffer size + pub so_rcvbuf: Option, // Skip serializing field because they contain secrets #[serde(skip_serializing)] root_ca_certificate_base64: Option, @@ -511,14 +515,17 @@ validated_struct::validator! { #[serde(skip_serializing)] connect_certificate_base64 : Option, }, + pub tcp: #[derive(Default)] + TcpConf { + /// Configure TCP write buffer size + pub so_sndbuf: Option, + /// Configure TCP read buffer size + pub so_rcvbuf: Option, + }, pub unixpipe: #[derive(Default)] UnixPipeConf { file_access_mask: Option }, - /// Configure TCP read buffer size - pub tcp_rx_buffer: Option, - /// Configure TCP write buffer size - pub tcp_tx_buffer: Option, }, pub shared_memory: ShmConf { diff --git a/io/zenoh-link-commons/src/lib.rs b/io/zenoh-link-commons/src/lib.rs index ed6f5e72f..6165a36a3 100644 --- a/io/zenoh-link-commons/src/lib.rs +++ b/io/zenoh-link-commons/src/lib.rs @@ -45,8 +45,8 @@ use zenoh_result::ZResult; /*************************************/ pub const BIND_INTERFACE: &str = "iface"; -pub const TCP_TX_BUFFER_SIZE: &str = "tcp_tx_buffer"; -pub const TCP_RX_BUFFER_SIZE: &str = "tcp_rx_buffer"; +pub const TCP_SO_SND_BUF: &str = "so_sndbuf"; +pub const TCP_SO_RCV_BUF: &str = "so_rcvbuf"; #[derive(Clone, Debug, Serialize, Hash, PartialEq, Eq)] pub struct Link { diff --git a/io/zenoh-links/zenoh-link-tcp/src/utils.rs b/io/zenoh-links/zenoh-link-tcp/src/utils.rs index 496969319..6772bc8f9 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/utils.rs @@ -13,8 +13,7 @@ // use zenoh_config::Config as ZenohConfig; use zenoh_link_commons::{ - tcp::TcpSocketConfig, ConfigurationInspector, BIND_INTERFACE, TCP_RX_BUFFER_SIZE, - TCP_TX_BUFFER_SIZE, + tcp::TcpSocketConfig, ConfigurationInspector, BIND_INTERFACE, TCP_SO_RCV_BUF, TCP_SO_SND_BUF, }; use zenoh_protocol::core::{parameters, Config}; use zenoh_result::{zerror, ZResult}; @@ -25,17 +24,17 @@ pub struct TcpConfigurator; impl ConfigurationInspector for TcpConfigurator { fn inspect_config(&self, config: &ZenohConfig) -> ZResult { let mut ps: Vec<(&str, &str)> = vec![]; - let c = config.transport().link(); + let c = config.transport().link().tcp(); let rx_buffer_size; - if let Some(size) = c.tcp_rx_buffer { + if let Some(size) = c.so_rcvbuf() { rx_buffer_size = size.to_string(); - ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size)); + ps.push((TCP_SO_RCV_BUF, &rx_buffer_size)); } let tx_buffer_size; - if let Some(size) = c.tcp_tx_buffer { + if let Some(size) = c.so_sndbuf() { tx_buffer_size = size.to_string(); - ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size)); + ps.push((TCP_SO_SND_BUF, &tx_buffer_size)); } Ok(parameters::from_iter(ps.drain(..))) @@ -56,13 +55,13 @@ impl<'a> TcpLinkConfig<'a> { bind_iface: config.get(BIND_INTERFACE), }; - if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_RCV_BUF) { tcp_config.rx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, ); }; - if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_SND_BUF) { tcp_config.tx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, diff --git a/io/zenoh-links/zenoh-link-tls/src/utils.rs b/io/zenoh-links/zenoh-link-tls/src/utils.rs index 9d96fbda6..32a5f929a 100644 --- a/io/zenoh-links/zenoh-link-tls/src/utils.rs +++ b/io/zenoh-links/zenoh-link-tls/src/utils.rs @@ -33,7 +33,7 @@ use webpki::anchor_from_trusted_cert; use zenoh_config::Config as ZenohConfig; use zenoh_link_commons::{ tcp::TcpSocketConfig, tls::WebPkiVerifierAnyServerName, ConfigurationInspector, BIND_INTERFACE, - TCP_RX_BUFFER_SIZE, TCP_TX_BUFFER_SIZE, + TCP_SO_RCV_BUF, TCP_SO_SND_BUF, }; use zenoh_protocol::core::{ endpoint::{Address, Config}, @@ -153,17 +153,16 @@ impl ConfigurationInspector for TlsConfigurator { false => ps.push((TLS_CLOSE_LINK_ON_EXPIRATION, "false")), } - let link_c = config.transport().link(); let rx_buffer_size; - if let Some(size) = link_c.tcp_rx_buffer { + if let Some(size) = c.so_rcvbuf() { rx_buffer_size = size.to_string(); - ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size)); + ps.push((TCP_SO_RCV_BUF, &rx_buffer_size)); } let tx_buffer_size; - if let Some(size) = link_c.tcp_tx_buffer { + if let Some(size) = c.so_sndbuf() { tx_buffer_size = size.to_string(); - ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size)); + ps.push((TCP_SO_SND_BUF, &tx_buffer_size)); } Ok(parameters::from_iter(ps.drain(..))) @@ -259,14 +258,14 @@ impl<'a> TlsServerConfig<'a> { ); let mut tcp_rx_buffer_size = None; - if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_RCV_BUF) { tcp_rx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, ); }; let mut tcp_tx_buffer_size = None; - if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_SND_BUF) { tcp_tx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, @@ -426,14 +425,14 @@ impl<'a> TlsClientConfig<'a> { }; let mut tcp_rx_buffer_size = None; - if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_RCV_BUF) { tcp_rx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?, ); }; let mut tcp_tx_buffer_size = None; - if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) { + if let Some(size) = config.get(TCP_SO_SND_BUF) { tcp_tx_buffer_size = Some( size.parse() .map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?, diff --git a/zenoh/tests/tcp_buffers.rs b/zenoh/tests/tcp_buffers.rs index c443f1489..8d9bb4ac8 100644 --- a/zenoh/tests/tcp_buffers.rs +++ b/zenoh/tests/tcp_buffers.rs @@ -19,11 +19,11 @@ fn buffer_size_config() { let mut config = Config::default(); config .insert_json5( - "transport/link", + "transport/link/tcp", r#" { - tcp_tx_buffer: 65000, - tcp_rx_buffer: 65000, + so_sndbuf: 65000, + so_rcvbuf: 65000, } "#, ) @@ -42,7 +42,7 @@ fn buffer_size_endpoint() { config .insert_json5( "listen/endpoints", - r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + r#"["tcp/[::]:0#so_sndbuf=65000;so_rcvbuf=65000"]"#, ) .unwrap(); @@ -54,11 +54,11 @@ fn buffer_size_endpoint_overwrite() { let mut config = Config::default(); config .insert_json5( - "transport/link", + "transport/link/tcp", r#" { - tcp_tx_buffer: 0, - tcp_rx_buffer: 0, + so_sndbuf: 0, + so_rcvbuf: 0, } "#, ) @@ -67,7 +67,7 @@ fn buffer_size_endpoint_overwrite() { config .insert_json5( "listen/endpoints", - r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#, + r#"["tcp/[::]:0#so_sndbuf=65000;so_rcvbuf=65000"]"#, ) .unwrap(); @@ -92,7 +92,7 @@ fn listen_zero_buffers() { config .insert_json5( "listen/endpoints", - r#"["tcp/[::]:0#tcp_tx_buffer=0;tcp_rx_buffer=0"]"#, + r#"["tcp/[::]:0#so_sndbuf=0;so_rcvbuf=0"]"#, ) .unwrap(); zenoh::open(config).wait().unwrap();