Bandwidth Delay Product Calculator

Calculate BDP for TCP buffer tuning and get recommended window sizes and sysctl settings.

Часто задаваемые вопросы

Реализация кода

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.