viewof numDevices = Inputs.range([10, 5000], {
value: 1200,
step: 50,
label: "Number of IoT devices:",
format: x => x.toLocaleString()
})
viewof channelsPerDevice = Inputs.range([1, 10], {
value: 4,
step: 1,
label: "Channels per device (message streams):"
})
viewof tcpHandshakeMs = Inputs.range([50, 500], {
value: 150,
step: 50,
label: "TCP handshake latency (ms):",
format: x => `${x} ms`
})
viewof socketMemoryKB = Inputs.range([4, 32], {
value: 16,
step: 4,
label: "Memory per TCP socket (KB):",
format: x => `${x} KB`
})
// Calculations
totalLogicalStreams = numDevices * channelsPerDevice
// Without multiplexing: one TCP connection per stream
withoutMuxConnections = totalLogicalStreams
withoutMuxHandshakeTime = withoutMuxConnections * tcpHandshakeMs / 1000 // seconds
withoutMuxMemory = withoutMuxConnections * socketMemoryKB / 1024 // MB
// With multiplexing: one TCP connection per device
withMuxConnections = numDevices
withMuxHandshakeTime = withMuxConnections * tcpHandshakeMs / 1000 // seconds
withMuxMemory = withMuxConnections * socketMemoryKB / 1024 // MB
// Savings
connectionReduction = withoutMuxConnections - withMuxConnections
handshakeSavings = withoutMuxHandshakeTime - withMuxHandshakeTime
memorySavings = withoutMuxMemory - withMuxMemory
reductionPercent = (connectionReduction / withoutMuxConnections) * 100
isNarrowMux = typeof window !== 'undefined' && window.innerWidth < 700
html`<div style="background: #f8f9fa; border-left: 4px solid #2C3E50; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Channel Multiplexing Impact</h4>
<div style="display: grid; grid-template-columns: ${isNarrowMux ? '1fr' : '1fr 1fr'}; gap: 15px; margin-bottom: 15px;">
<div style="background: #fee; padding: 12px; border-radius: 4px; border: 2px solid #E74C3C;">
<div style="color: #E74C3C; font-weight: bold; margin-bottom: 10px;">Without Multiplexing</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">TCP Connections</div>
<div style="color: #2C3E50; font-size: 20px; font-weight: bold;">${withoutMuxConnections.toLocaleString()}</div>
</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Handshake Time</div>
<div style="color: #2C3E50; font-size: 16px;">${withoutMuxHandshakeTime.toFixed(1)} sec</div>
</div>
<div>
<div style="color: #7F8C8D; font-size: 11px;">Broker Memory</div>
<div style="color: #2C3E50; font-size: 16px;">${withoutMuxMemory.toFixed(1)} MB</div>
</div>
</div>
<div style="background: #efe; padding: 12px; border-radius: 4px; border: 2px solid #16A085;">
<div style="color: #16A085; font-weight: bold; margin-bottom: 10px;">With Multiplexing</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">TCP Connections</div>
<div style="color: #2C3E50; font-size: 20px; font-weight: bold;">${withMuxConnections.toLocaleString()}</div>
</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Handshake Time</div>
<div style="color: #2C3E50; font-size: 16px;">${withMuxHandshakeTime.toFixed(1)} sec</div>
</div>
<div>
<div style="color: #7F8C8D; font-size: 11px;">Broker Memory</div>
<div style="color: #2C3E50; font-size: 16px;">${withMuxMemory.toFixed(1)} MB</div>
</div>
</div>
</div>
<div style="background: linear-gradient(135deg, #16A085 0%, #3498DB 100%); padding: 15px; border-radius: 4px; color: white;">
<div style="font-size: 14px; font-weight: bold; margin-bottom: 10px;">Savings with Channel Multiplexing</div>
<div style="display: grid; grid-template-columns: ${isNarrowMux ? '1fr' : 'repeat(3, 1fr)'}; gap: 10px;">
<div>
<div style="font-size: 11px; opacity: 0.9;">Connections Reduced</div>
<div style="font-size: 22px; font-weight: bold;">${connectionReduction.toLocaleString()}</div>
<div style="font-size: 11px; opacity: 0.9;">${reductionPercent.toFixed(0)}% reduction</div>
</div>
<div>
<div style="font-size: 11px; opacity: 0.9;">Time Saved</div>
<div style="font-size: 22px; font-weight: bold;">${handshakeSavings.toFixed(1)}s</div>
<div style="font-size: 11px; opacity: 0.9;">Connection setup</div>
</div>
<div>
<div style="font-size: 11px; opacity: 0.9;">Memory Saved</div>
<div style="font-size: 22px; font-weight: bold;">${memorySavings.toFixed(1)} MB</div>
<div style="font-size: 11px; opacity: 0.9;">Broker RAM</div>
</div>
</div>
</div>
<div style="margin-top: 12px; padding: 10px; background: white; border-radius: 4px; font-size: 13px; color: #2C3E50; border: 1px solid #e0e0e0;">
<strong>Example:</strong> ${numDevices.toLocaleString()} devices with ${channelsPerDevice} message streams each = ${totalLogicalStreams.toLocaleString()} logical channels.
With multiplexing, only ${withMuxConnections.toLocaleString()} TCP connections are needed (${channelsPerDevice}x reduction).
</div>
`Channel Multiplexing Savings
Channel Multiplexing Savings
animation
amqp
protocols
messaging
Try Set channels per device to 4 and change the number of IoT devices.
Observe Compare TCP Connections and Broker Memory with 4 channels per device.
Explain Explain why 4 message streams per device need fewer TCP connections with multiplexing.
Technical boundaries. Without multiplexing, the model uses one TCP connection per stream; with multiplexing, one per device. Handshake time and memory use fixed per-connection inputs.
Tip
Checkpoint: Broker and Channel Basics
Checkpoint: Broker and Channel Basics
You now know:
- Producer, broker, and consumer are separate roles; the producer sends once and does not need to know which consumers exist.
- The broker owns exchanges, bindings, queues, persistence, acknowledgments, and flow control.
- Channel multiplexing lets one TCP connection carry many logical streams while channel errors remain isolated from other channels.