Skip to content

Commit

Permalink
increase TCP send/recv buffer size
Browse files Browse the repository at this point in the history
- ref ##745, significantly increase thoughtput, but still slower than
system network stack
  • Loading branch information
zonyitoo committed Jan 17, 2022
1 parent add0fb6 commit 13c5de0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/shadowsocks-service/src/local/tun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ impl Tun {
packet = self.udp.recv_packet() => {
if let Err(err) = write_packet_with_pi(&mut self.device, &packet).await {
error!("[TUN] failed to set packet information, error: {}, {:?}", err, ByteStr::new(&packet));
} else {
trace!("[TUN] sent IP packet (UDP) {:?}", ByteStr::new(&packet));
}
}

// TCP channel sent back
packet = self.tcp.recv_packet() => {
if let Err(err) = write_packet_with_pi(&mut self.device, &packet).await {
error!("[TUN] failed to set packet information, error: {}, {:?}", err, ByteStr::new(&packet));
} else {
trace!("[TUN] sent IP packet (TCP) {:?}", ByteStr::new(&packet));
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/shadowsocks-service/src/local/tun/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ impl TcpTun {
// TCP first handshake packet, create a new Connection
if tcp_packet.syn() && !tcp_packet.ack() {
let accept_opts = self.context.accept_opts();
let send_buffer_size = accept_opts.tcp.send_buffer_size.unwrap_or(4096);
let recv_buffer_size = accept_opts.tcp.recv_buffer_size.unwrap_or(4096);
// NOTE: Default value is taken from Linux
// recv: /proc/sys/net/ipv4/tcp_rmem 87380 bytes
// send: /proc/sys/net/ipv4/tcp_wmem 16384 bytes
let send_buffer_size = accept_opts.tcp.send_buffer_size.unwrap_or(16384);
let recv_buffer_size = accept_opts.tcp.recv_buffer_size.unwrap_or(87380);

let mut socket = TcpSocket::new(
TcpSocketBuffer::new(vec![0u8; recv_buffer_size as usize]),
Expand Down

0 comments on commit 13c5de0

Please sign in to comment.