Files
NetMesh/components/notes/test-fixtures/issue-3205.md
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

3.0 KiB
Raw Blame History

设备TCP栈调优操作记录

目标根据本地带宽动态调整TCP接收/发送缓冲区使其能容纳带宽延迟积BDP

1. 环境信息收集

1.1 基础硬件与系统信息

# 设备型号
cat /tmp/sysinfo/model

# 内核版本
uname -r

# 总内存
grep MemTotal /proc/meminfo

1.2 当前TCP参数快照

sysctl net.ipv4.tcp_rmem \
       net.ipv4.tcp_wmem \
       net.core.rmem_max \
       net.core.wmem_max \
       net.ipv4.tcp_congestion_control \
       net.core.netdev_max_backlog

1.3 网络链路与带宽测试

  • 查看WAN口速率(替换<wan口>为实际接口名,如eth0
    ethtool <wan口> | grep -i speed
    
  • 实测带宽(确保无代理干扰):
    # 检查代理进程
    ps | grep -E "openclash|mihomo"
    
    # 若存在代理,请先关闭;然后测速
    speedtest --accept-license --format=json
    

1.4 检查BBR拥塞控制算法支持

cat /proc/sys/net/ipv4/tcp_available_congestion_control

注意:若输出不包含bbr,则后续配置保持cubic


2. BDP计算与参数确定

2.1 计算公式

最大缓冲区(MB) ≈ 带宽(Mbps) × 0.125 × 最大RTT(秒)
即:带宽(Mbps) × 0.125 × (RTT_ms / 1000)

2.2 参数参考

场景 预估RTT 推荐max
本地网络 ~30ms 根据实测带宽计算
代理/国际链路 ~150-200ms 根据实测带宽计算
内存<1GB设备 - 固定16MB
大内存服务器 - 可参考GCP建议最大64MB

2.3 配置示例16MB

若计算后决定使用16MB上限

cat > /etc/sysctl.d/90-tcp-tuning.conf <<'EOF'
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 131072 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.core.netdev_max_backlog = 8192
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_slow_start_after_idle = 0
EOF

3. 应用与验证

3.1 加载配置

# 应用配置文件BusyBox使用-p参数
sysctl -p /etc/sysctl.d/90-tcp-tuning.conf

3.2 验证生效

# 检查关键参数
sysctl net.ipv4.tcp_rmem net.core.rmem_max

3.3 本地环回吞吐测试

# 启动临时服务端运行1次后退出
iperf3 -s -1 &

# 客户端连接本机测试3秒
iperf3 -c 127.0.0.1 -t 3

目的验证内核TCP栈本身是否正常。


4. 重要说明

  • 开机自动加载OpenWrt系统下/etc/init.d/sysctl会自动遍历/etc/sysctl.d/*.conf,无需额外设置。
  • BBR支持若内核不支持BBR不添加net.ipv4.tcp_congestion_control=bbr保留默认cubic。
  • 故障排查:外网测速慢时,请先排除:
    • 代理软件openclash/mihomo劫持流量。
    • 上游运营商或国际链路瓶颈。
  • 配置回滚:如需恢复默认设置,只需:
    rm /etc/sysctl.d/90-tcp-tuning.conf
    sysctl -p /etc/sysctl.d/90-tcp-tuning.conf  # 或重启设备