viewof numConsumers = Inputs.range([1, 100], {
value: 50,
step: 1,
label: "Number of consumers"
})
viewof avgProcessingTime = Inputs.range([10, 300], {
value: 45,
step: 1,
label: "Average processing time (sec)"
})
viewof processingVariance = Inputs.range([0, 200], {
value: 50,
step: 5,
label: "Processing time variance (%)"
})
viewof targetLatency = Inputs.range([0.1, 10], {
value: 1,
step: 0.1,
label: "Target latency (sec)"
})
// Calculate optimal prefetch
optimalPrefetch = Math.max(1, Math.ceil(targetLatency / avgProcessingTime))
throughputPerConsumer = 3600 / avgProcessingTime
totalThroughput = throughputPerConsumer * numConsumers
fastestConsumer = avgProcessingTime * (1 - processingVariance / 100)
slowestConsumer = avgProcessingTime * (1 + processingVariance / 100)
// High prefetch problems
highPrefetch = 10
messagesLockedToSlow = highPrefetch * (numConsumers * 0.2) // 20% slow consumers
lockTimeSeconds = highPrefetch * slowestConsumer
html`<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #16A085;">
<h3 style="margin-top: 0; color: #2C3E50;">Optimal Prefetch Configuration</h3>
<div style="background: white; padding: 20px; border-radius: 6px; border: 1px solid #ddd; margin-bottom: 20px;">
<h4 style="color: #16A085; margin-top: 0;">Recommended Prefetch Count</h4>
<p style="font-size: 48px; font-weight: bold; color: #16A085; margin: 10px 0;">
${optimalPrefetch}
</p>
<p style="color: #7F8C8D; margin: 5px 0;">
Based on ${targetLatency}s target latency and ${avgProcessingTime}s average processing
</p>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; margin-top: 15px;">
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #2C3E50; margin-top: 0;">System Capacity</h4>
<p style="margin: 8px 0;">
<span style="color: #7F8C8D;">Per consumer:</span>
<strong>${throughputPerConsumer.toFixed(1)} orders/hr</strong>
</p>
<p style="margin: 8px 0;">
<span style="color: #7F8C8D;">Total fleet:</span>
<strong>${totalThroughput.toLocaleString()} orders/hr</strong>
</p>
<p style="margin: 8px 0;">
<span style="color: #7F8C8D;">Processing range:</span>
<strong>${fastestConsumer.toFixed(1)}-${slowestConsumer.toFixed(1)}s</strong>
</p>
</div>
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #E74C3C; margin-top: 0;">High Prefetch Risk (prefetch=10)</h4>
<p style="margin: 8px 0;">
<span style="color: #7F8C8D;">Messages locked:</span>
<strong>~${messagesLockedToSlow.toFixed(0)} messages</strong>
</p>
<p style="margin: 8px 0;">
<span style="color: #7F8C8D;">Lock duration:</span>
<strong>${(lockTimeSeconds / 60).toFixed(1)} minutes</strong>
</p>
<p style="margin: 8px 0; color: #E74C3C;">
<strong> Prefetch starvation risk</strong>
</p>
</div>
</div>
<div style="margin-top: 20px; padding: 15px; background: white; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #2C3E50; margin-top: 0;">Formula</h4>
<p style="font-family: monospace; color: #7F8C8D; margin: 10px 0;">
prefetch = max(1, ceil(target_latency / avg_processing_time))
</p>
<p style="color: #7F8C8D; font-size: 0.95em; margin-top: 15px;">
<strong>Rule of thumb:</strong> For variable processing times, start with prefetch=1 for fairness, then tune the setting against throughput and workload.
</p>
</div>
</div>`Interactive: Prefetch Calculator
Interactive: Prefetch Calculator
animation
amqp
protocols
messaging
Try Change Average processing time (sec) from 45 to 10.
Observe Watch Recommended Prefetch Count and System Capacity as average processing time changes from 45 seconds.
Explain Explain why prefetch=1 follows from the target latency and average processing time.
Technical boundaries. Prefetch uses max(1, ceil(target_latency / avg_processing_time)). High prefetch risk assumes prefetch=10 and 20% slow consumers; total throughput uses average processing time and number of consumers.