viewof vizPrefetch = Inputs.range([1, 50], {
value: 1,
step: 1,
label: "Prefetch count"
})
viewof vizFastConsumers = Inputs.range([1, 10], {
value: 3,
step: 1,
label: "Fast consumers (10ms each)"
})
viewof vizSlowConsumers = Inputs.range([1, 10], {
value: 2,
step: 1,
label: "Slow consumers (500ms each)"
})
viewof vizQueueDepth = Inputs.range([10, 500], {
value: 100,
step: 10,
label: "Messages in queue"
})Try It: Prefetch Starvation Visualizer
Try It: Prefetch Starvation Visualizer
animation
amqp
protocols
messaging
Try Change Prefetch count from 1 to 50.
Observe Watch Consumer Message Distribution and Buffer drain as prefetch increases from 1.
Explain Explain why 500ms processing changes Buffer drain and Hoarding compared with 10ms processing.
Technical boundaries. Distribution gives each consumer the same buffer, limited by prefetch and queue depth. Processing is fixed at 10ms or 500ms; total system throughput depends on consumer counts rather than prefetch.
NoteTry It: Prefetch Starvation Visualizer
See how different prefetch counts affect message distribution across fast and slow consumers. Watch how high prefetch values cause slow consumers to hoard messages while fast consumers idle.
vizTotalConsumers = vizFastConsumers + vizSlowConsumers
vizMsgsPerConsumer = Math.min(vizPrefetch, Math.floor(vizQueueDepth / vizTotalConsumers))
vizMsgsToSlow = vizMsgsPerConsumer * vizSlowConsumers
vizMsgsToFast = vizMsgsPerConsumer * vizFastConsumers
vizMsgsAvailable = vizQueueDepth - vizMsgsToSlow - vizMsgsToFast
// Time to process prefetch buffer
vizFastBufferTime = vizMsgsPerConsumer * 10 // 10ms each
vizSlowBufferTime = vizMsgsPerConsumer * 500 // 500ms each
// Effective throughput
vizFastThroughput = vizFastConsumers * (1000 / 10) // msg/sec per fast consumer
vizSlowThroughput = vizSlowConsumers * (1000 / 500) // msg/sec per slow consumer
vizTotalThroughput = vizFastThroughput + vizSlowThroughput
// Starvation detection
vizFastIdleTime = Math.max(0, vizSlowBufferTime - vizFastBufferTime)
vizStarvationRisk = vizPrefetch > 5 && vizSlowConsumers > 0
vizSlowHoardPercent = vizQueueDepth > 0 ? ((vizMsgsToSlow / vizQueueDepth) * 100) : 0
html`<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #E74C3C;">
<h3 style="margin-top: 0; color: #2C3E50;">Consumer Message Distribution</h3>
<div style="margin: 15px 0;">
<p style="color: #2C3E50; font-weight: bold; margin-bottom: 8px;">Queue: ${vizQueueDepth} messages</p>
<div style="display: flex; height: 36px; border-radius: 6px; overflow: hidden; border: 1px solid #ddd;">
<div style="width: ${(vizMsgsToFast / vizQueueDepth) * 100}%; background: #16A085; display: flex; align-items: center; justify-content: center; color: white; font-size: 0.8em; font-weight: bold; transition: width 0.3s;">
${vizMsgsToFast > 0 ? `Fast: ${vizMsgsToFast}` : ''}
</div>
<div style="width: ${(vizMsgsToSlow / vizQueueDepth) * 100}%; background: #E74C3C; display: flex; align-items: center; justify-content: center; color: white; font-size: 0.8em; font-weight: bold; transition: width 0.3s;">
${vizMsgsToSlow > 0 ? `Slow: ${vizMsgsToSlow}` : ''}
</div>
<div style="width: ${(vizMsgsAvailable / vizQueueDepth) * 100}%; background: #ecf0f1; display: flex; align-items: center; justify-content: center; color: #7F8C8D; font-size: 0.8em; transition: width 0.3s;">
${vizMsgsAvailable > 0 ? `Available: ${vizMsgsAvailable}` : ''}
</div>
</div>
</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: #16A085; margin-top: 0;">Fast Consumers (x${vizFastConsumers})</h4>
<p style="margin: 6px 0; color: #7F8C8D;">Processing: 10ms/msg</p>
<p style="margin: 6px 0; color: #7F8C8D;">Buffer: ${vizMsgsPerConsumer} msgs each</p>
<p style="margin: 6px 0; color: #7F8C8D;">Buffer drain: ${vizFastBufferTime}ms</p>
<p style="margin: 6px 0; color: #16A085; font-weight: bold;">Throughput: ${vizFastThroughput.toFixed(0)} msg/sec</p>
${vizFastIdleTime > 0
? `<p style="margin: 6px 0; color: #E67E22; font-weight: bold;">Idle for ${(vizFastIdleTime / 1000).toFixed(1)}s waiting for slow consumers to finish</p>`
: `<p style="margin: 6px 0; color: #16A085;">No idle time</p>`}
</div>
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #E74C3C; margin-top: 0;">Slow Consumers (x${vizSlowConsumers})</h4>
<p style="margin: 6px 0; color: #7F8C8D;">Processing: 500ms/msg</p>
<p style="margin: 6px 0; color: #7F8C8D;">Buffer: ${vizMsgsPerConsumer} msgs each</p>
<p style="margin: 6px 0; color: #7F8C8D;">Buffer drain: ${(vizSlowBufferTime / 1000).toFixed(1)}s</p>
<p style="margin: 6px 0; color: #E74C3C; font-weight: bold;">Throughput: ${vizSlowThroughput.toFixed(1)} msg/sec</p>
<p style="margin: 6px 0; color: #7F8C8D;">Hoarding: ${vizSlowHoardPercent.toFixed(1)}% of queue</p>
</div>
</div>
<div style="margin-top: 15px; padding: 15px; background: ${vizStarvationRisk ? '#fff3cd' : '#d4edda'}; border-radius: 6px; border: 1px solid ${vizStarvationRisk ? '#E67E22' : '#16A085'};">
<p style="margin: 0; color: #2C3E50; font-weight: bold;">
${vizStarvationRisk
? 'Starvation Risk: Slow consumers lock ' + vizMsgsToSlow + ' messages for ' + (vizSlowBufferTime / 1000).toFixed(1) + 's. Fast consumers drain their buffer in ' + vizFastBufferTime + 'ms and must wait. Set prefetch=1 for fair distribution.'
: 'Healthy Distribution: With prefetch=' + vizPrefetch + ', messages are distributed efficiently. Fast consumers process and request new messages quickly without long waits.'}
</p>
</div>
<div style="margin-top: 15px; padding: 12px; background: white; border-radius: 6px; border: 1px solid #ddd;">
<p style="margin: 0; color: #7F8C8D; font-size: 0.9em;">
<strong>Total system throughput:</strong> ${vizTotalThroughput.toFixed(0)} msg/sec |
<strong>Fast consumer share:</strong> ${((vizFastThroughput / vizTotalThroughput) * 100).toFixed(0)}% |
<strong>Queue drain time:</strong> ${(vizQueueDepth / vizTotalThroughput).toFixed(1)}s
</p>
</div>
</div>`