{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# The Bandwidth–Delay Product Knee\n",
        "\n",
        "A single-bottleneck model separates the inflight data that sustains throughput from the extra data that adds queueing delay.\n",
        "\n",
        "Static single-bottleneck fluid accounting with declared capacity, RTT, and buffer; not BBR implementation, loss-rate measurement, or current-version benchmark.\n",
        "\n",
        "The code uses Python 3 and the standard library. Saved output is from the checked CPU run.\n"
      ],
      "id": "inflight-data-has-a-throughput-0"
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "source": [
        "capacity_bps = 100_000_000\n",
        "capacity_bytes_s = capacity_bps / 8\n",
        "base_rtt_s = 0.040\n",
        "buffer_bytes = 500_000\n",
        "bdp_bytes = capacity_bytes_s * base_rtt_s\n",
        "\n",
        "def model(offered_bytes):\n",
        "    admitted = min(offered_bytes, bdp_bytes + buffer_bytes)\n",
        "    excess = offered_bytes - admitted\n",
        "    queued = max(admitted - bdp_bytes, 0.0)\n",
        "    rtt = base_rtt_s + queued / capacity_bytes_s\n",
        "    delivery = min(capacity_bytes_s, admitted / base_rtt_s)\n",
        "    assert abs(admitted / rtt - delivery) < 1e-6\n",
        "    assert queued <= buffer_bytes and excess >= 0\n",
        "    return delivery * 8 / 1e6, rtt * 1000, queued, excess\n",
        "\n",
        "print(f\"BDP={bdp_bytes:.0f} bytes; buffer={buffer_bytes} bytes\")\n",
        "observations = []\n",
        "for offered in [125_000, 500_000, 750_000, 1_500_000]:\n",
        "    rate, rtt, queue, excess = model(offered)\n",
        "    observations.append((rate, rtt))\n",
        "    print(f\"offered={offered:7d} rate={rate:6.1f}Mbps RTT={rtt:5.1f}ms \"\n",
        "          f\"queue={queue:.0f} excess={excess:.0f} bytes\")\n",
        "\n",
        "assert max(rate for rate, _ in observations) == 100.0\n",
        "assert min(rtt for _, rtt in observations) == 40.0\n",
        "print(\"Static fluid-model consistency checks: passed\")\n"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "BDP=500000 bytes; buffer=500000 bytes\n",
            "offered= 125000 rate=  25.0Mbps RTT= 40.0ms queue=0 excess=0 bytes\n",
            "offered= 500000 rate= 100.0Mbps RTT= 40.0ms queue=0 excess=0 bytes\n",
            "offered= 750000 rate= 100.0Mbps RTT= 60.0ms queue=250000 excess=0 bytes\n",
            "offered=1500000 rate= 100.0Mbps RTT= 80.0ms queue=500000 excess=500000 bytes\n",
            "Static fluid-model consistency checks: passed\n"
          ]
        }
      ],
      "id": "inflight-data-has-a-throughput-1"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Sources\n",
        "\n",
        "- BBR: Congestion-Based Congestion Control (2016): https://research.google/pubs/bbr-congestion-based-congestion-control-2/\n- Original BBR paper, author text in Stanford course archive: https://web.stanford.edu/class/cs244/papers/bbr.pdf\n"
      ],
      "id": "inflight-data-has-a-throughput-2"
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.12.14"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
