viewof sensorsOnGateway = Inputs.range([5, 200], {value: 50, step: 5, label: "Sensors on gateway"})
viewof readingInterval = Inputs.range([1, 60], {value: 10, step: 1, label: "Reading interval (seconds)"})
viewof networkRtt = Inputs.range([10, 500], {value: 100, step: 10, label: "Network RTT (ms)"})
viewof poolSize = Inputs.range([1, 50], {value: 10, step: 1, label: "Connection pool size"})Connection Churn vs Keep-Alive Calculator
Connection Churn vs Keep-Alive Calculator
animation
http
app-protocols
Try Increase Connection pool size while keeping the load fixed. Then press Calculate connection efficiency.
Observe After pressing Calculate connection efficiency, watch per request latency and max throughput as Connection pool size changes.
Explain Explain why Connection pool size changes amortized setup cost after you press Calculate connection efficiency.
Technical boundaries. TCP, TLS and HTTP times use fixed multiples of network RTT. Setup cost is divided by pool size.
NoteTry It: Connection Churn vs Keep-Alive Calculator
{
const reqPerSec = sensorsOnGateway / readingInterval;
const reqPerMin = reqPerSec * 60;
// No keep-alive: full TCP+TLS+HTTP per request
const tcpMs = networkRtt * 1.5;
const tlsMs = networkRtt * 2.0;
const httpMs = networkRtt * 1.0;
const noKaLatency = tcpMs + tlsMs + httpMs;
const noKaThroughput = (1000 / noKaLatency);
// With keep-alive pool: amortized setup
const kaSetupCost = (tcpMs + tlsMs) / poolSize;
const kaLatency = httpMs + kaSetupCost;
const kaThroughput = poolSize * (1000 / httpMs);
const canHandle = reqPerSec <= kaThroughput;
const noKaCanHandle = reqPerSec <= noKaThroughput;
const latencyReduction = ((noKaLatency - kaLatency) / noKaLatency * 100).toFixed(1);
const cpuSavings = ((1 - 1/poolSize) * 100).toFixed(0);
return html`
<div style="font-family: Arial, sans-serif; padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #3498DB;">
<p style="margin-top: 0; margin-bottom: 0.8em; color: #2C3E50; font-weight: 700; font-size: 1.1em;">Gateway Connection Efficiency</p>
<div style="background: white; padding: 12px 15px; border-radius: 6px; margin-bottom: 15px;">
<span style="color: #7F8C8D; font-size: 0.9em;">Load: <strong style="color: #2C3E50;">${sensorsOnGateway} sensors</strong> x 1 reading/${readingInterval}s = <strong style="color: #2C3E50;">${reqPerMin.toFixed(0)} requests/min</strong> (${reqPerSec.toFixed(1)} req/s)</span>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px;">
<div style="background: white; padding: 15px; border-radius: 6px; border-top: 3px solid #E67E22;">
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 8px;">No Keep-Alive (new conn per req)</div>
<div style="font-size: 1.8em; font-weight: bold; color: #E67E22;">${noKaLatency.toFixed(0)}ms</div>
<div style="font-size: 0.85em; color: #7F8C8D;">per request latency</div>
<div style="margin-top: 10px; font-size: 0.85em; color: #7F8C8D;">
TCP: ${tcpMs.toFixed(0)}ms + TLS: ${tlsMs.toFixed(0)}ms + HTTP: ${httpMs.toFixed(0)}ms
</div>
<div style="margin-top: 8px; padding: 6px 10px; border-radius: 4px; font-size: 0.85em; background: ${noKaCanHandle ? '#e8f5e9' : '#ffebee'}; color: ${noKaCanHandle ? '#16A085' : '#E74C3C'};">
Max throughput: ${noKaThroughput.toFixed(1)} req/s ${noKaCanHandle ? '(sufficient)' : '(OVERLOADED!)'}
</div>
</div>
<div style="background: white; padding: 15px; border-radius: 6px; border-top: 3px solid #16A085;">
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 8px;">Keep-Alive Pool (${poolSize} connections)</div>
<div style="font-size: 1.8em; font-weight: bold; color: #16A085;">${kaLatency.toFixed(0)}ms</div>
<div style="font-size: 0.85em; color: #7F8C8D;">per request latency</div>
<div style="margin-top: 10px; font-size: 0.85em; color: #7F8C8D;">
Amortized setup: ${kaSetupCost.toFixed(0)}ms + HTTP: ${httpMs.toFixed(0)}ms
</div>
<div style="margin-top: 8px; padding: 6px 10px; border-radius: 4px; font-size: 0.85em; background: ${canHandle ? '#e8f5e9' : '#ffebee'}; color: ${canHandle ? '#16A085' : '#E74C3C'};">
Max throughput: ${kaThroughput.toFixed(0)} req/s ${canHandle ? '(sufficient)' : '(OVERLOADED!)'}
</div>
</div>
</div>
<div style="background: white; padding: 12px 15px; border-radius: 6px;">
<strong style="color: #16A085;">Latency reduction: ${latencyReduction}%</strong> | <strong style="color: #3498DB;">TLS handshake savings: ~${cpuSavings}%</strong><br/>
<span style="color: #7F8C8D; font-size: 0.85em;">
Each pooled connection serves ~${Math.ceil(reqPerMin / poolSize)} requests/min, amortizing the ${(tcpMs + tlsMs).toFixed(0)}ms setup cost across ${poolSize} reuses.
</span>
</div>
</div>
`;
}