Skip to content

Commit b19086a

Browse files
apollo_network: increased TCP window size
1 parent 89741fe commit b19086a

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# does not build, only copies the binary and entrypoint.sh from the local machine
1+
# does not build, only copies the binary from the local machine
22
FROM ubuntu:24.04
33

4-
RUN apt update && apt -y install iproute2 kmod chrony && apt clean && rm -rf /var/lib/apt/lists/*
4+
RUN apt update && apt -y install iproute2 kmod chrony net-tools tcpdump && apt clean && rm -rf /var/lib/apt/lists/*
55

66
COPY --from=tmp broadcast_network_stress_test_node /usr/local/bin/broadcast_network_stress_test_node
77
COPY ./crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/entrypoint.sh /entrypoint.sh
8+
COPY ./crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/tcp_config.sh /tcp_config.sh
89

910
RUN chmod +x /entrypoint.sh
11+
RUN chmod +x /tcp_config.sh
12+
13+
RUN /tcp_config.sh
1014

1115
ENTRYPOINT ["/entrypoint.sh"]

crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/Dockerfile.slow

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ RUN RUSTFLAGS="--cfg tokio_unstable" cargo build --release --bin broadcast_netwo
2727
# --- Final Stage: Runtime image ---
2828
FROM ubuntu:24.04 AS final_stage
2929

30-
RUN apt update && apt -y install iproute2 kmod chrony && apt clean && rm -rf /var/lib/apt/lists/*
30+
# Install network tools and BBR congestion control support
31+
RUN apt update && apt -y install iproute2 kmod chrony net-tools tcpdump && apt clean && rm -rf /var/lib/apt/lists/*
3132

33+
# Copy application and TCP configuration script (runs at container startup)
3234
COPY --from=builder /app/target/release/broadcast_network_stress_test_node /usr/local/bin/broadcast_network_stress_test_node
3335
COPY --from=builder /app/crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/entrypoint.sh /entrypoint.sh
36+
COPY --from=builder /app/crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/tcp_config.sh /tcp_config.sh
3437

3538
RUN chmod +x /entrypoint.sh
39+
RUN chmod +x /tcp_config.sh
40+
41+
RUN /tcp_config.sh
3642

3743
ENTRYPOINT ["/entrypoint.sh"]

crates/apollo_network/src/bin/broadcast_network_stress_test_node/run/entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fi
1414

1515
# ********************************* machine information *********************************
1616

17+
echo "##################################################################################"
18+
1719
echo "Machine identification:"
1820
echo " Container ID: $(cat /proc/self/cgroup 2>/dev/null | head -1 | cut -d/ -f3 | cut -c1-12 || echo 'N/A')"
1921
echo " Host IP addresses:"
@@ -27,6 +29,7 @@ fi
2729
if [ -n "$KUBERNETES_NODE_NAME" ]; then
2830
echo " K8s Node Name: $KUBERNETES_NODE_NAME"
2931
fi
32+
echo "##################################################################################"
3033

3134
# ***************************** throttling connection start *****************************
3235

@@ -73,6 +76,18 @@ apply_shaping() {
7376
# Apply to ingress (ifb0)
7477
apply_shaping ifb0 "root" "1"
7578

79+
# ***************************** print network configuration *****************************
80+
81+
echo "##################################################################################"
82+
cat /etc/sysctl.conf
83+
echo "##################################################################################"
84+
sysctl -a | grep -i tcp
85+
echo "##################################################################################"
86+
ifconfig
87+
echo "##################################################################################"
88+
netstat -i
89+
echo "##################################################################################"
90+
7691
# ***************************** throttling connection end *****************************
7792

7893
# Call broadcast_network_stress_test_node
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Fixed window size: 64MB (67108864 bytes)
5+
WINDOW_SIZE=67108864
6+
7+
# General core socket buffer limits
8+
echo "net.core.rmem_max = 1073741824" > /etc/sysctl.conf
9+
echo "net.core.wmem_max = 1073741824" >> /etc/sysctl.conf
10+
echo "net.ipv4.tcp_rmem = 262144 1048576 1073741824" >> /etc/sysctl.conf
11+
echo "net.ipv4.tcp_wmem = 262144 1048576 1073741824" >> /etc/sysctl.conf
12+
13+
# sysctl -p

crates/apollo_network/src/network_manager/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,39 @@ impl NetworkManager {
831831
}
832832
None => Keypair::generate_ed25519(),
833833
};
834+
// Configure TCP transport for HIGH THROUGHPUT, HIGH LATENCY scenarios
835+
// Note: TCP keepalive to maintain long-lived connections during inactivity is typically
836+
// configured at the OS level via sysctl parameters (tcp_keepalive_time,
837+
// tcp_keepalive_intvl, tcp_keepalive_probes). Nodelay is enabled by default to
838+
// reduce latency.
839+
let tcp_config = libp2p::tcp::Config::default().nodelay(true); // Explicitly disable Nagle's algorithm for immediate sending
840+
841+
// Configure Yamux for MAXIMUM THROUGHPUT without waiting for acknowledgments
842+
let yamux_config = {
843+
let mut config = libp2p::yamux::Config::default();
844+
// CRITICAL: Set receive window size to 32 MiB per stream (matching TCP buffer capacity)
845+
// This allows the sender to transmit up to 32 MiB of data per stream before
846+
// waiting for window updates, which works with our 64MB TCP buffers and is essential
847+
// for high-bandwidth, high-latency scenarios.
848+
// Note: This method is deprecated but functional. It will be replaced with
849+
// a connection-level receive window in a future libp2p release.
850+
#[allow(deprecated)]
851+
config.set_receive_window_size(32 * 1024 * 1024); // 32 MiB per stream
852+
853+
// Set max buffer size to match the receive window
854+
#[allow(deprecated)]
855+
config.set_max_buffer_size(32 * 1024 * 1024); // 32 MiB per stream
856+
857+
// Allow maximum concurrent streams for parallel data transmission
858+
config.set_max_num_streams(4096); // increased from default 512 for maximum parallelism
859+
860+
config
861+
};
862+
834863
let mut swarm = SwarmBuilder::with_existing_identity(key_pair)
835864
.with_tokio()
836865
// TODO(AndrewL): .with_quic()
837-
.with_tcp(Default::default(), noise::Config::new, yamux::Config::default)
866+
.with_tcp(tcp_config, noise::Config::new, || yamux_config.clone())
838867
.expect("Error building TCP transport")
839868
.with_dns()
840869
.expect("Error building DNS transport")

0 commit comments

Comments
 (0)