feat(tcp): optimize TCP socket configuration for 4M-64M data chunk transfers
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
e6a0b9372d
commit
f869b306ed
|
|
@ -20,10 +20,10 @@ pub mod tcp;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// DEFAULT_SEND_BUFFER_SIZE is the default size of the send buffer for network connections.
|
/// DEFAULT_SEND_BUFFER_SIZE is the default size of the send buffer for network connections.
|
||||||
const DEFAULT_SEND_BUFFER_SIZE: usize = 4 * 1024 * 1024;
|
const DEFAULT_SEND_BUFFER_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// DEFAULT_RECV_BUFFER_SIZE is the default size of the receive buffer for network connections.
|
/// DEFAULT_RECV_BUFFER_SIZE is the default size of the receive buffer for network connections.
|
||||||
const DEFAULT_RECV_BUFFER_SIZE: usize = 4 * 1024 * 1024;
|
const DEFAULT_RECV_BUFFER_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// DEFAULT_KEEPALIVE_INTERVAL is the default interval for sending keepalive messages.
|
/// DEFAULT_KEEPALIVE_INTERVAL is the default interval for sending keepalive messages.
|
||||||
const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(5);
|
const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,15 @@ impl TCPClient {
|
||||||
socket.set_tcp_keepalive(
|
socket.set_tcp_keepalive(
|
||||||
&TcpKeepalive::new().with_interval(super::DEFAULT_KEEPALIVE_INTERVAL),
|
&TcpKeepalive::new().with_interval(super::DEFAULT_KEEPALIVE_INTERVAL),
|
||||||
)?;
|
)?;
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
use tracing::warn;
|
||||||
|
if let Err(err) = socket.set_tcp_fastopen(true) {
|
||||||
|
warn!("failed to set tcp fast open: {}", err);
|
||||||
|
} else {
|
||||||
|
info!("set tcp fast open");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let (reader, mut writer) = stream.into_split();
|
let (reader, mut writer) = stream.into_split();
|
||||||
writer.write_all(&request).await.inspect_err(|err| {
|
writer.write_all(&request).await.inspect_err(|err| {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,10 @@ pub mod tcp;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// DEFAULT_SEND_BUFFER_SIZE is the default size of the send buffer for network connections.
|
/// DEFAULT_SEND_BUFFER_SIZE is the default size of the send buffer for network connections.
|
||||||
const DEFAULT_SEND_BUFFER_SIZE: usize = 4 * 1024 * 1024;
|
const DEFAULT_SEND_BUFFER_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// DEFAULT_RECV_BUFFER_SIZE is the default size of the receive buffer for network connections.
|
/// DEFAULT_RECV_BUFFER_SIZE is the default size of the receive buffer for network connections.
|
||||||
const DEFAULT_RECV_BUFFER_SIZE: usize = 4 * 1024 * 1024;
|
const DEFAULT_RECV_BUFFER_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// DEFAULT_KEEPALIVE_INTERVAL is the default interval for sending keepalive messages.
|
/// DEFAULT_KEEPALIVE_INTERVAL is the default interval for sending keepalive messages.
|
||||||
const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(5);
|
const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,17 @@ impl TCPServer {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
if let Err(err) = socket.set_tcp_congestion("bbr".as_bytes()) {
|
if let Err(err) = socket.set_tcp_congestion("cubic".as_bytes()) {
|
||||||
warn!("failed to set tcp congestion: {}", err);
|
warn!("failed to set tcp congestion: {}", err);
|
||||||
|
} else {
|
||||||
|
info!("set tcp congestion to cubic");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(err) = socket.set_tcp_fastopen(true) {
|
||||||
|
warn!("failed to set tcp fast open: {}", err);
|
||||||
|
} else {
|
||||||
|
info!("set tcp fast open");
|
||||||
}
|
}
|
||||||
info!("set tcp congestion to bbr");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.bind(&self.addr.into())?;
|
socket.bind(&self.addr.into())?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue