跳到内容
🛠️ToolsShed

Bandwidth Delay Product Calculator

计算BDP以用于TCP缓冲优化,并获取推荐的窗口大小和sysctl设置。

关于此工具

带宽时延积(BDP)是链路带宽与往返时间的乘积,它准确地告诉你在任一时刻线路上可以承载多少在途数据。这个数值决定了在长肥网络上实现满吞吐所需的理想 TCP 窗口,因为在这类高速度与高时延并存的网络中,过小的窗口会悄悄地限制你的传输速度。

使用时,输入链路带宽和往返时延,然后读取得出的 BDP 和建议的 TCP 窗口大小。它专为网络工程师、调优吞吐量的系统管理员,以及任何排查高时延链路上传输缓慢问题的人而设计。

提示:如果 TCP 窗口小于 BDP,链路就会闲置等待 ACK,吞吐量随之下降,因此请按此调整缓冲区大小。所有计算都在你的浏览器本地完成。

常见问题

代码实现

def bandwidth_delay_product(bandwidth_mbps: float, rtt_ms: float) -> dict:
    """
    Calculate Bandwidth-Delay Product (BDP).
    BDP = Bandwidth × RTT
    This represents the amount of data in transit (in flight) at any time.
    """
    bandwidth_bps = bandwidth_mbps * 1_000_000
    rtt_sec = rtt_ms / 1000

    bdp_bits = bandwidth_bps * rtt_sec
    bdp_bytes = bdp_bits / 8
    bdp_kb = bdp_bytes / 1024
    bdp_mb = bdp_kb / 1024

    # Recommended TCP window size (2x BDP for headroom)
    tcp_window_bytes = int(bdp_bytes * 2)

    return {
        "bdp_bits": int(bdp_bits),
        "bdp_bytes": int(bdp_bytes),
        "bdp_kb": round(bdp_kb, 2),
        "bdp_mb": round(bdp_mb, 4),
        "tcp_window_recommended_bytes": tcp_window_bytes,
        "tcp_window_recommended_kb": round(tcp_window_bytes / 1024, 1),
    }

# Examples
scenarios = [
    ("Home broadband", 100, 20),
    ("Transatlantic fiber", 1000, 70),
    ("Satellite internet", 50, 600),
    ("Data center", 10_000, 1),
]

for name, bw, rtt in scenarios:
    r = bandwidth_delay_product(bw, rtt)
    print(f"{name} ({bw} Mbps, {rtt}ms RTT):")
    print(f"  BDP: {r['bdp_kb']:.1f} KB ({r['bdp_mb']:.2f} MB)")
    print(f"  Recommended TCP window: {r['tcp_window_recommended_kb']:.0f} KB")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.