viewof numSensors = Inputs.range([10, 10000], {
value: 200,
step: 10,
label: "Number of sensors"
})
viewof messageRatePerSensor = Inputs.range([1, 60], {
value: 1,
step: 1,
label: "Messages per minute per sensor"
})
viewof offlineHours = Inputs.range([1, 168], {
value: 60,
step: 1,
label: "Offline period (hours)"
})
viewof messageSizeBytes = Inputs.range([50, 5000], {
value: 150,
step: 50,
label: "Message payload size (bytes)"
})
viewof processingHours = Inputs.range([0.5, 24], {
value: 3,
step: 0.5,
label: "Processing window (hours)"
})
// Calculations
messagesPerHour = numSensors * messageRatePerSensor * 60
totalMessages = messagesPerHour * offlineHours
amqpOverhead = 80 // AMQP metadata overhead
totalBytesPerMessage = messageSizeBytes + amqpOverhead
totalStorageMB = (totalMessages * totalBytesPerMessage) / (1024 * 1024)
safetyMargin = 1.2
requiredStorageMB = totalStorageMB * safetyMargin
requiredMessageCapacity = Math.ceil(totalMessages * safetyMargin)
requiredThroughput = totalMessages / (processingHours * 3600)
recommendedWorkers = Math.ceil(requiredThroughput / 10) // Assume 10 msg/sec per worker
html`<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #9B59B6;">
<h3 style="margin-top: 0; color: #2C3E50;">Queue Capacity Requirements</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-top: 15px;">
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #9B59B6; margin-top: 0;">Message Volume</h4>
<p style="font-size: 32px; font-weight: bold; color: #9B59B6; margin: 10px 0;">
${totalMessages.toLocaleString()}
</p>
<p style="color: #7F8C8D; margin: 5px 0;">
${messagesPerHour.toLocaleString()} msg/hr for ${offlineHours} hours
</p>
<p style="color: #E67E22; font-weight: bold; margin-top: 15px;">
Recommended capacity: ${requiredMessageCapacity.toLocaleString()} messages
</p>
<p style="color: #7F8C8D; font-size: 0.9em; margin: 5px 0;">
(includes 20% safety margin)
</p>
</div>
<div style="background: white; padding: 15px; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #9B59B6; margin-top: 0;">Storage Requirements</h4>
<p style="font-size: 32px; font-weight: bold; color: #9B59B6; margin: 10px 0;">
${requiredStorageMB.toFixed(1)} MB
</p>
<p style="color: #7F8C8D; margin: 5px 0;">
${messageSizeBytes}B payload + ${amqpOverhead}B overhead = ${totalBytesPerMessage}B per message
</p>
<p style="color: #7F8C8D; font-size: 0.9em; margin-top: 10px;">
Base: ${totalStorageMB.toFixed(1)} MB + 20% margin
</p>
</div>
</div>
<div style="margin-top: 20px; padding: 20px; background: white; border-radius: 6px; border: 1px solid #ddd;">
<h4 style="color: #2C3E50; margin-top: 0;">Processing Requirements</h4>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px;">
<div>
<p style="color: #7F8C8D; margin: 5px 0;">Required throughput:</p>
<p style="font-size: 24px; font-weight: bold; color: #E67E22; margin: 5px 0;">
${requiredThroughput.toFixed(1)} <span style="font-size: 14px; font-weight: normal;">msg/sec</span>
</p>
</div>
<div>
<p style="color: #7F8C8D; margin: 5px 0;">Recommended workers:</p>
<p style="font-size: 24px; font-weight: bold; color: #16A085; margin: 5px 0;">
${recommendedWorkers} <span style="font-size: 14px; font-weight: normal;">consumers</span>
</p>
</div>
<div>
<p style="color: #7F8C8D; margin: 5px 0;">Per-worker rate:</p>
<p style="font-size: 24px; font-weight: bold; color: #3498DB; margin: 5px 0;">
${(requiredThroughput / recommendedWorkers).toFixed(1)} <span style="font-size: 14px; font-weight: normal;">msg/sec</span>
</p>
</div>
</div>
</div>
<div style="margin-top: 20px; padding: 20px; background: #fff3cd; border-radius: 6px; border: 1px solid #E67E22;">
<h4 style="color: #2C3E50; margin-top: 0;">Queue Configuration</h4>
<pre style="background: #2C3E50; color: #16A085; padding: 15px; border-radius: 4px; overflow-x: auto; font-size: 0.9em; margin: 10px 0;"><code>channel.queue_declare(
queue='batch-processing',
durable=True,
arguments={
'x-max-length': ${requiredMessageCapacity},
'x-max-length-bytes': ${Math.ceil(requiredStorageMB * 1024 * 1024)},
'x-overflow': 'reject-publish',
'x-message-ttl': ${Math.ceil(offlineHours * 1.2 * 3600000)}, # ${(offlineHours * 1.2).toFixed(1)} hrs
'x-dead-letter-exchange': 'batch-dlx'
}
)</code></pre>
</div>
</div>`Interactive: Queue Sizing Calculator
Interactive: Queue Sizing Calculator
animation
amqp
protocols
messaging
Try Change Offline period (hours) from 60 to 168.
Observe Watch Message Volume, Storage Requirements, and Processing Requirements as the offline period increases from 60 hours.
Explain Explain why the 20% safety margin increases recommended capacity and storage requirements.
Technical boundaries. Messages accumulate during offline periods. Storage adds 80 B of AMQP metadata overhead per message and a 20% safety margin; recommended workers assume 10 msg/sec per worker.