Buffer Bloat & BDP Sizing Tool
function bdpBytes(bwMbps, rttMs) {
return (bwMbps * 1e6 / 8) * (rttMs / 1000);
}
function fmtBytes(b) {
if (b >= 1e9) return (b/1e9).toFixed(2) + ' GB';
if (b >= 1e6) return (b/1e6).toFixed(2) + ' MB';
if (b >= 1e3) return (b/1e3).toFixed(1) + ' KB';
return Math.round(b) + ' B';
}
// Build reference table
(function buildRefTable() {
const table = document.getElementById('bdpRefTable');
BW_ROWS.forEach(bw => {
const tr = document.createElement('tr');
const label = bw >= 1000 ? `${bw/1000} Gbps` : `${bw} Mbps`;
tr.innerHTML = `${label} `;
RTT_COLS.forEach(rtt => {
const bytes = bdpBytes(bw, rtt);
tr.innerHTML += `${fmtBytes(bytes)} `;
});
table.appendChild(tr);
});
})();
function calcBdp() {
const bw = parseFloat(document.getElementById('bwMbps').value);
const rtt = parseFloat(document.getElementById('rttMs').value);
const bufMs = parseFloat(document.getElementById('bufMs').value);
const div = document.getElementById('bdpResult');
const section = document.getElementById('bdpResultSection');
section.style.display = 'block';
div.style.display = 'block';
if (isNaN(bw) || isNaN(rtt) || bw <= 0 || rtt <= 0) {
div.innerHTML = '
AQM Recommendation:${bloatHtml}`;
}
Enter valid bandwidth (> 0 Mbps) and RTT (> 0 ms).
';
return;
}
const bdp = bdpBytes(bw, rtt);
const bufBytes = !isNaN(bufMs) && bufMs > 0 ? bdpBytes(bw, bufMs) : null;
const bufRatio = bufBytes ? bufBytes / bdp : null;
const bloat = bufRatio !== null && bufRatio > 4;
// AQM recommendation
let aqmRec = 'fq_codel';
let aqmReason = 'general-purpose, excellent for most scenarios';
if (bw < 20) { aqmRec = 'CAKE'; aqmReason = 'low-bandwidth link — CAKE\'s shaping prevents queue buildup'; }
else if (bufRatio && bufRatio > 10) { aqmRec = 'CAKE'; aqmReason = 'severe buffer bloat — CAKE + shaping will reclaim latency'; }
let bloatHtml = '';
if (bufBytes !== null) {
const cls = bloat ? 'warn' : 'good';
bloatHtml = `
Buffer analysis: ${fmtBytes(bufBytes)} buffer (${bufMs} ms at ${bw} Mbps)
Buffer / BDP ratio: ${bufRatio.toFixed(1)}×
${bloat ? `Buffer bloat likely. Buffer is ${bufRatio.toFixed(1)}× the BDP. Latency under load may spike by ~${Math.round(bufMs - rtt)} ms.` : `Buffer sizing looks reasonable. Buffer is ${bufRatio.toFixed(1)}× the BDP.`}
`;
}
div.innerHTML = `Buffer / BDP ratio: ${bufRatio.toFixed(1)}×
${bloat ? `Buffer bloat likely. Buffer is ${bufRatio.toFixed(1)}× the BDP. Latency under load may spike by ~${Math.round(bufMs - rtt)} ms.` : `Buffer sizing looks reasonable. Buffer is ${bufRatio.toFixed(1)}× the BDP.`}
${fmtBytes(bdp)}
BDP (bandwidth × RTT / 8)
${(bdp/1500).toFixed(0)}
BDP in 1500-byte packets
${bw} Mbps
Link bandwidth
${rtt} ms
RTT
AQM Recommendation:
${aqmRec} — ${aqmReason}