Troubleshooting
Why QoS 2 messages stall in an MQTT load test, then arrive late
Short answer
The stall is a backlog, not loss. The inject counter counts triggers, not completed publishes, and QoS 2's four-packet handshake retains state per in-flight message, so 40,000 messages every 0.5 s outrun a path draining roughly 30,000 msg/s; the backlog arrives as a tail after the generator stops. Count at each boundary before calling it loss.

On this page
A QoS 2 load test that races to batch 25-40 and then "stops sending" is almost never losing messages. In the flow that shows this symptom, the counter on the dashboard counts inject triggers, not completed MQTT transactions, and the QoS 2 handshake makes each message far more expensive than QoS 0 or 1. The offered load outruns what the single-processor virtual machine can complete, the backlog grows in memory, and the remainder drains as a tail after the generator stops. The fix is to measure at each boundary and then lower the offered rate; the messages are late, not gone.
What the counter actually counts #
The generator flow uses an inject node repeating every 0.5 seconds with a counter limit of 50. Each trigger fans out to 10 subflows, each with 200 MQTT client connections, and each client publishes 20 topics. The counter function increments once per trigger and stops passing messages after the limit, so "counter finished" means 50 triggers fired, not that 2,000,000 messages were published. The run therefore offers:
- 2,000 clients x 20 topics = 40,000 messages per trigger
- 40,000 / 0.5 s = 80,000 messages per second offered while triggers continue
- 50 triggers x 40,000 = 2,000,000 messages scheduled in total
When the counter jumps through its remaining counts in under a second, the triggers are simply being consumed on schedule. The messages those triggers created are still queued in Node-RED, in the MQTT.js clients, or at the broker.
The configured path #
Each publish travels from the function output, through the MQTT Out node and its MQTT.js connection, over the guest's virtual interface to the broker, and finally to the subscriber behind the dashboard. The broker config in the flow sets the parameters that matter for diagnosis:
| Setting | Configured value | Diagnostic meaning |
|---|---|---|
| Broker address | 192.168.0.82 | Capture on the interface carrying this address |
| Port | 1883, usetls false | Plain MQTT, no TLS to decode |
| protocolVersion | 4 | MQTT 3.1.1; decode captures at this level |
| keepalive | 60 seconds | A starved event loop can miss keepalive servicing and disconnect |
| cleansession | true, empty clientid | A reconnect cannot resume the previous broker session state |
Node-RED and the broker run inside one Ubuntu virtual machine with 16 GB of RAM and one allocated processor, so Node.js, the MQTT.js clients, the broker and the guest kernel all contend for that single core.
Why QoS 2 reaches the wall first #
QoS 0 sends a PUBLISH with no delivery handshake. QoS 1 retains state until PUBACK. QoS 2 completes a four-packet exchange: PUBLISH, PUBREC, PUBREL, PUBCOMP, with both endpoints holding transaction state until the exchange finishes. Every unfinished QoS 2 publication consumes an in-flight slot, memory and extra packet processing on both ends; the QoS is a separate agreement between each client and the broker, so 2,000 clients each maintain their own in-flight state. Once a client reaches its in-flight limit, a conforming implementation applies backpressure or queues later publishes, and the backlog moves upstream into the client and the flow. That is the stall you see: the inject counter keeps climbing while the publisher can no longer accept work at the offered rate.
The forum owner's own results with a separate benchmark tool confirm the mechanism is not Node-RED-specific: that tool also published about 31,000 messages per second and produced the same tail.
Counting at each boundary #
Before calling anything lost, record separate counts at four boundaries:
- The generator function output: how many messages the flow created.
- The MQTT Out node, using complete and catch nodes: how many publishes completed and how many errored or reconnected.
- Broker ingress: the broker's own received-message counter, or a packet capture on TCP port 1883 showing PUBLISH packets and their PUBREC responses.
- The subscriber or dashboard input: how many messages were delivered.
Also watch per-process CPU in the guest throughout the run. If the single allocated processor stays saturated while queue delay rises, the machine is the limit, not a broker bug. If connections drop, check whether the disconnects line up with the 60-second keepalive: a flooded event loop can fail to service keepalives even when the network path is healthy, and with cleansession true the broker discards the session state at each disconnect.
| Observed symptom | Likely condition | Reading that decides it |
|---|---|---|
| Counter reaches 50 but broker count stalls | Counter records triggers, not publishes | Compare function-output count with captured PUBLISH count |
| More topics per client breaks it sooner | More per-connection work and QoS 2 state | Outstanding transactions and memory per connection |
| Messages arrive after the generator stops | Backlog draining, not loss | Measure the drain time after counts stabilize |
| Catch-node errors or reconnects | Client queue, socket or session failure | Correlate errors with TCP resets and broker logs |
Working the backlog arithmetic for the observed run #
One benchmark run with this flow reported 1,802,746 publications received by the broker side while the dashboard showed 405,621 delivered, and the remaining messages took about 47 seconds to arrive after the benchmark stopped.
Inputs, all from that run's log and dashboard: published = 1,802,746 messages; delivered when the generator stopped = 405,621 messages; tail duration = 47 seconds; offered rate = 80,000 messages per second (40,000 per 0.5 s trigger).
The rule: the backlog is the difference between what was published and what was delivered; the drain rate is the backlog divided by the tail time.
Arithmetic:
- Backlog = 1,802,746 - 405,621 = 1,397,125 messages
- Drain rate = 1,397,125 / 47 s = approximately 29,700 messages per second
Result: the delivery path completes about 29,700 messages per second while the flow offers 80,000 per second. Queue growth follows: growth = max(0, offered - completed) x time, so about 50,000 messages per second of net backlog during generation. At the same time, a measured QoS 0 burst of 40,000 messages took 2.86 seconds to emit, roughly 14,000 messages per second for the publish side alone.
Decision: because the tail delivered every outstanding message and no messages were dropped, this run demonstrated backlog, not loss. The threshold to act on: whenever the offered rate exceeds the measured completion rate of the slowest boundary, the run is invalid as a loss test. Re-run with the trigger interval raised until the completion counts track the offered count in real time, and only then judge whether anything is actually lost. For the same reason the owner's QoS 1 runs took roughly three times as long to arrive at the broker as their QoS 0 equivalents: more handshake, slower completion, longer tail.
When delayed becomes lost #
The backlog explanation holds only while the clients stay connected. If the keepalive is missed because the event loop is flooded, the broker disconnects the client, and with cleansession true and an empty client ID the pending QoS 2 state is discarded; only then are messages genuinely lost, at disconnect, not during the stall. That is why the boundary counts matter: a falling complete-node count with a rising catch-node count, correlated with connection drops in the broker log, is real loss; a stable difference that drains to zero is delay.
If the goal of the test is to size a production pipeline that must not lose messages at this scale, a broker-to-broker or MQTT-to-Kafka design is the usual answer; our article on an MQTT to Kafka edge data pipeline covers that architecture, and buffering MQTT messages while the broker connection is down covers the store-and-forward side. For this generator test itself, the decision is simpler: keep QoS 2 for correctness tests at the rate your hardware completes, and expect any offered load above that rate to queue, stall and tail, never to vanish.
Questions asked
Why does QoS 0 run clean while QoS 2 stalls?
QoS 0 sends one PUBLISH with no handshake, QoS 1 holds state until PUBACK, and QoS 2 completes PUBLISH, PUBREC, PUBREL and PUBCOMP with both endpoints retaining transaction state. Every unfinished QoS 2 publication occupies an in-flight slot and costs more packets and CPU, so the same hardware completes far fewer of them per second.
Does a reconnect during the test lose the queued QoS 2 state?
In this flow yes: cleansession is true and the client ID is empty, so a disconnect discards the broker-side session and pending QoS state cannot be resumed. A starved event loop can also miss keepalive servicing, which triggers exactly such a disconnect. Check the broker connection log against the 60-second keepalive before assuming message loss.
Will raising the client queue or in-flight limits fix the stall?
No. Increasing a queue or in-flight limit without lowering the arrival rate only postpones exhaustion and raises memory demand, because the offered rate still exceeds what the path completes. Lower the trigger rate, reduce topics per client, or spread the load across more than one processor before touching limits.


