viewof gatewayRam = Inputs.select([64, 128, 256, 512, 1024], {value: 256, label: "Gateway RAM (MB)"})
viewof maxPayloadLimit = Inputs.range([0.1, 50], {value: 1, step: 0.1, label: "Max payload limit (MB)"})
viewof concurrentRequests = Inputs.range([1, 100], {value: 20, step: 1, label: "Concurrent requests"})
viewof enableCompression = Inputs.checkbox(["Enable gzip decompression"], {value: []})Payload Size Impact Simulator
Payload Size Impact Simulator
animation
http
app-protocols
Try Increase Concurrent requests while keeping the payload limit fixed. Then press Calculate memory impact.
Observe After pressing Calculate memory impact, watch peak memory and available RAM usage as Concurrent requests changes.
Explain Explain why Concurrent requests changes peak memory after you press Calculate memory impact.
Technical boundaries. The model reserves 20% of RAM for the OS and 30 MB for the app. Decompression uses a fixed 10-fold payload expansion.
NoteTry It: Payload Size Impact Simulator
{
const isCompressed = enableCompression.length > 0;
const compressionRatio = 10; // zip bomb worst case
const effectivePayload = isCompressed ? maxPayloadLimit * compressionRatio : maxPayloadLimit;
const peakMemory = effectivePayload * concurrentRequests;
const osOverhead = gatewayRam * 0.2; // ~20% for OS
const appOverhead = 30; // ~30MB app baseline
const availableRam = gatewayRam - osOverhead - appOverhead;
const memoryUsage = (peakMemory / availableRam * 100);
const isSafe = memoryUsage < 80;
const isCritical = memoryUsage >= 100;
const safeMaxPayload = (availableRam * 0.8 / concurrentRequests).toFixed(1);
const safeMaxPayloadCompressed = (safeMaxPayload / compressionRatio).toFixed(2);
const barWidth = Math.min(memoryUsage, 150);
const barColor = isCritical ? "#E74C3C" : isSafe ? "#16A085" : "#E67E22";
return html`
<div style="font-family: Arial, sans-serif; padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #9B59B6;">
<p style="margin-top: 0; margin-bottom: 0.8em; color: #2C3E50; font-weight: 700; font-size: 1.1em;">Gateway Memory Impact Analysis</p>
<div style="background: white; padding: 15px; border-radius: 6px; margin-bottom: 15px;">
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 8px;">
Peak memory: <strong>${concurrentRequests}</strong> concurrent requests x <strong>${effectivePayload.toFixed(1)} MB</strong> ${isCompressed ? '(after decompression)' : ''} each
</div>
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
<div style="flex-grow: 1; height: 24px; background: #e0e0e0; border-radius: 4px; overflow: hidden; position: relative;">
<div style="width: ${Math.min(barWidth, 100)}%; height: 100%; background: ${barColor}; border-radius: 4px; transition: width 0.3s;"></div>
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 0.8em; font-weight: bold; color: ${barWidth > 50 ? 'white' : '#2C3E50'};">${memoryUsage.toFixed(0)}% of available RAM</div>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 0.8em;">
<div style="padding: 6px 8px; background: #f0f0f0; border-radius: 4px;">
<div style="color: #7F8C8D;">Total RAM</div>
<div style="font-weight: bold; color: #2C3E50;">${gatewayRam} MB</div>
</div>
<div style="padding: 6px 8px; background: #f0f0f0; border-radius: 4px;">
<div style="color: #7F8C8D;">Available</div>
<div style="font-weight: bold; color: #2C3E50;">${availableRam.toFixed(0)} MB</div>
</div>
<div style="padding: 6px 8px; background: #f0f0f0; border-radius: 4px;">
<div style="color: #7F8C8D;">Peak Usage</div>
<div style="font-weight: bold; color: ${barColor};">${peakMemory.toFixed(1)} MB</div>
</div>
</div>
</div>
${isCompressed ? html`
<div style="background: #fff3e0; padding: 10px 15px; border-radius: 6px; margin-bottom: 15px; font-size: 0.9em;">
<strong style="color: #E67E22;">Compression warning:</strong> A ${maxPayloadLimit.toFixed(1)} MB compressed payload can expand to ${effectivePayload.toFixed(1)} MB (${compressionRatio}x ratio). Always set decompression limits!
</div>
` : ''}
<div style="background: ${isCritical ? '#ffebee' : isSafe ? '#e8f5e9' : '#fff3e0'}; padding: 12px 15px; border-radius: 6px;">
${isCritical
? html`<strong style="color: #E74C3C;">CRASH RISK!</strong><span style="color: #7F8C8D; font-size: 0.9em;"> Peak memory (${peakMemory.toFixed(0)} MB) exceeds available RAM (${availableRam.toFixed(0)} MB). Set <code>client_max_body_size</code> to <strong>${safeMaxPayload} MB</strong>${isCompressed ? ` (or ${safeMaxPayloadCompressed} MB compressed)` : ''}.</span>`
: isSafe
? html`<strong style="color: #16A085;">Safe configuration.</strong><span style="color: #7F8C8D; font-size: 0.9em;"> Memory usage within 80% threshold. Current limit allows headroom for spikes.</span>`
: html`<strong style="color: #E67E22;">Warning: approaching memory limit.</strong><span style="color: #7F8C8D; font-size: 0.9em;"> Consider reducing max payload to <strong>${safeMaxPayload} MB</strong> for a safer margin.</span>`
}
</div>
</div>
`;
}