Message Queuing Telemetry Transport (MQTT) Ping Load
The MQTT ping load makes many emulated devices of the User Services Platform (USP) send a ping request (PINGREQ) at the same moment. The broker answers each PINGREQ with a ping response (PINGRESP). The emulator measures the answers. The result shows where the broker or the emulator reaches its limit.
The load works with these devices only:
-
USP devices with the message transfer protocol (MTP) of MQTT.
-
Started devices.
-
Devices with MQTT keep-alive 0.
Keep-alive is the time between two pings of a device to the broker. The load does not change the normal behaviour of a device. A device has at most one forced PINGREQ open at a time. The load sends no second PINGREQ, forces no reconnect and sends no Boot! message.
Keep-alive must be 0
A device with MQTT keep-alive greater than 0 pings the broker by itself. The load skips such a device. The status counts the skip as skippedKeepAlive. Prometheus counts the skip in emulator_mqtt_ping_skipped_total with the label reason="keep_alive".
To enable the load, set MTP Ping interval (sec) to 0 on the devices. The key is usp.mtp.ping_interval. The default value is already 0.
Check the broker setting Server Keep Alive too. The broker can override the keep-alive of the device.
The pings of devices with keep-alive greater than 0 have their own metrics. See Keep-alive ping metrics.
If the load finds no device for a PINGREQ, the start call answers 409. The message gives the reason:
-
No started USP device with MTP MQTT. -
All <n> started USP MQTT devices have MQTT keep-alive > 0; set usp.mtp.ping_interval=0 or check the broker’s Server Keep Alive. -
None of the <n> started USP MQTT devices is connected; retry when they are connected. -
No started USP MQTT device has MQTT keep-alive 0 (<n> devices: keep-alive > 0: <k>, not connected: <c>); set usp.mtp.ping_interval=0 or check the broker’s Server Keep Alive, or retry when the devices are connected.
During the MQTT connect, the keep-alive of a device is not known yet. Wait for the connect and send the start call again.
Start, status and stop
All sizes are per emulator instance. If you run 20 instances, each instance sends its own load.
The path is /api/devices/mqtt-ping. Swagger shows the calls under the tag MQTT ping load.
| Call | Path | Result |
|---|---|---|
|
|
|
|
|
|
|
|
|
The status has one of these states:
| State | Meaning |
|---|---|
|
No load runs. After a run ends, the status keeps the values of the run until the next run starts. |
|
The first slot of the current grid has not come yet. A |
|
The first slot has come. A run without |
Example body for a burst load with a ramp. The load starts now:
{
"mode": "BURST",
"intervalMs": 5000,
"durationSec": 300,
"ramp": { "from": 1000, "step": 1000, "burstsPerStep": 3, "to": 10000 }
}
Example body for a start at a fixed time. Replace the time with your own time:
{
"intervalMs": 5000,
"startAt": "2026-11-10T10:00:00Z"
}
The rule for startAt: at most 24 hours ahead. A time in the past works only with intervalMs.
When you control many instances, send the POST with one future startAt to every instance. Send all calls before startAt. Then the ramp steps up at the same moment on every instance. Compare nextSlot in each answer with startAt.
An empty body {} uses all defaults.
Because of the path /api/devices/mqtt-ping, you cannot reach a device with the clientId mqtt-ping at GET or DELETE /api/devices/{clientId}.
|
Parameters
All fields are optional. Numbers are integers. The emulator cuts off a fraction, so 1000.7 runs as 1000.
A POST replaces all parameters. A field you omit takes its default. The load does not keep the value of an earlier POST.
| Field | Values | Default | Description |
|---|---|---|---|
|
|
|
|
|
1 to 1,000,000 |
All eligible devices |
Number of devices for the load. If you give |
|
100 to 3,600,000 |
None |
Time between two slots in milliseconds. |
|
1 to 86,400 |
300 |
Run time in seconds. |
|
Time in Coordinated Universal Time (UTC), for example |
Now |
Start time on the wall clock. The time is at most 24 hours ahead. A time in the past works only with |
|
Object with |
None |
Growing burst size. Use |
A slot is a planned send time. A burst is the set of PINGREQ messages of one slot. Rules for the run:
-
The slots are
startAtplus a multiple ofintervalMs. -
The slots follow the wall clock. Instances with the same
startAtandintervalMsstay aligned. -
A run ends at
endsAt: the first slot of the phase plusdurationSec. -
A run without
intervalMssends one burst.DELETEends the run earlier. -
A new
POSTwhile the load runs starts a new phase. -
If
modeandintervalMsstay the same, the new phase continues the slot grid. OmitstartAtor keep its value. -
The continued grid starts the new phase at its next slot.
-
A change of
mode,intervalMsorstartAtcloses the open burst and starts a new grid. -
A new phase restarts the phase limit and
endsAt. -
The ramp counter restarts as the rules below describe.
-
The totals and the history continue.
-
If a 5-second grid runs, a
POSTwith{"devices": 2000}dropsintervalMs. The load closes the open burst and sends one burst. -
Stop or Reset of the emulator also stops the load. The load stops when the emulator is not initialized, too.
-
Burst
khasmin(from + k / burstsPerStep * step, to)devices. The division is a whole-number division. -
After
tothe size stays atto. -
If the
POSThas astartAt, the countkis the number of slots sincestartAt. -
A
POSTafterstartAtjoins the ramp at the step of the slots sincestartAt. -
The same
startAtin a repeatedPOSTkeeps the count. -
A new ramp then continues at the step for the time since
startAt. -
A new
startAtrestarts the count at 0. -
A
POSTwithoutstartAtcountskfrom the first slot of its phase, starting at 0. -
In
STEADYmode, the status gives one record for each wall-clock second. -
In
STEADYmode, the emulator sends in ticks of 10 ms. -
A PINGREQ in
STEADYmode can leave up to 10 ms after its planned time. -
In
BURSTmode, the emulator reads the list of devices about 20 ms before each slot. -
A device started less than about 20 ms before a slot joins the burst after that slot.
-
A device started after the
POSTjoins the next burst. -
In
STEADYmode, the emulator reads the list of devices every 10 seconds.
Errors
A 400 answer has the code MQTT_PING_INVALID. The message names the field, if the error has one. The causes are:
-
A value out of range.
-
A
modeother thanBURSTorSTEADY. -
An invalid
startAt. Use the form2026-11-10T10:00:00Z. -
A field with the wrong JavaScript Object Notation (JSON) type.
-
An unknown field, for example the typo
intervalMS. -
A missing body or a body with invalid JSON.
For a missing body or invalid JSON, the message is Request body is missing or is not valid JSON; send {} for the defaults.
A 409 answer has the code MQTT_PING_NO_DEVICES. See Keep-alive must be 0.
Read the result
The status has these top-level fields:
| Field | Meaning |
|---|---|
|
State of the load, and number of the current phase. The phase is 0 before the first run. |
|
The parameters of the current phase, with the defaults filled in. |
|
Number of started USP MQTT devices with keep-alive 0. |
|
Number of devices with a PINGREQ still open after its burst closed. |
|
Time of the next slot and the end of the run. If no load runs, both are |
|
Size of the open burst, or of the next burst. The value is never higher than |
|
The limit of the current phase, and the limits of all phases. See The limit. |
|
The open burst or second, with the numbers so far. |
|
The last 200 closed bursts or seconds. The newest record comes first. |
|
The sums over the run. See The totals. |
Each record in current and recent describes one burst. In STEADY mode, a record describes one second. The record fields are:
| Field | Meaning |
|---|---|
|
Type of the record ( |
|
Burst size from the ramp formula, and devices selected. |
|
Planned time of the slot, and real start. |
|
Time between the planned slot and the real start. In |
|
PINGREQ messages handed to the MQTT client. If |
|
Time between the first and the last PINGREQ of the burst. |
|
PINGRESP messages received before the burst closed. |
|
|
|
PINGREQ messages with no PINGRESP after a dropped connection. A reconnect or a stop of the connector gives the same result. |
|
Failed hand-offs of PINGREQ messages to the MQTT client. |
|
Dropped MQTT connections during the burst. |
|
Time until the last PINGRESP. If a PINGREQ stays unanswered at the close, or if no PINGRESP came back, the value is |
|
Answer time in milliseconds: the 50th percentile, the 99th percentile and the maximum. The values cover the answers before the close. See below. |
|
Devices that sent no PINGREQ, with the reason. |
|
|
The 50th percentile (p50) is the answer time of the middle PINGREQ. Half of the answers are as fast or faster.
The 99th percentile (p99) is an answer time. 99 of 100 answers are as fast or faster.
The maximum (max) is the slowest answer.
A burst closes at the first of these moments:
-
Each PINGREQ has an answer or has failed.
-
One interval has passed since the slot. A single burst closes after 60 seconds.
-
DELETE, or a Stop or Reset of the emulator, ends the run. The record showsstopped=true. -
A
POSTchangesmode,intervalMsorstartAt. The record showsstopped=true. -
The run ends. If the run ends before the normal close, the record shows
stopped=true.
If the hand-off of the PINGREQ messages takes longer than the interval, the burst closes when the hand-off ends. A status request does not cut the hand-off.
A POST closes a single burst with a finished hand-off as a normal close. The record shows stopped=false.
In STEADY mode, a record closes when the second has ended and each PINGREQ has an answer or has failed. Otherwise, the record closes one interval after the second ended. The same stop rules apply.
The unanswered count shows a slow broker. The failed and droppedConnections counts show a broken connection. With the status alone, you can tell the two causes apart.
Time values in the status are UTC in the form 2026-11-10T10:00:00.123Z with at most 3 fraction digits. The status leaves out the fraction on a whole second.
A device without an answer keeps waiting. The device skips every later burst until its PINGRESP arrives or its connection ends. The status shows these devices as waitingDevices.
The totals
The field totals has the sums of all closed bursts or seconds of the run. The field totals also has the run-wide counters.
-
windows,sent,answered,unanswered,failed,sendFailed: the sums of the records. -
skippedNotConnected,skippedWaiting,skippedKeepAlive: the sums of the records. -
missedSlots: slots or cycles the emulator skipped. The rules are in The limit. -
lateResponses: answers after the close of their burst. -
lateFailures: PINGREQ messages that failed after the close of their burst. -
lateResponsesandlateFailurescount only the bursts of the current run. Late answers of an earlier run do not count. -
droppedConnections: dropped MQTT connections since the run start.
The limit
The limit is the first burst of a phase with unanswered greater than 0. The load does not stop at the limit. You stop the load with DELETE. Alternatively, the duration ends the run.
To step up by hand, send one POST for each step, for example with devices 10000, then 20000. A POST without intervalMs sends a single burst. The next POST closes the previous single burst as a normal close. The unanswered count at that moment can set the limit of that phase. Wait until the answers have time to arrive before the next POST. The limit of that phase is in limits. For periodic bursts, keep intervalMs in every POST. Then the POST continues the grid.
-
limit: the limit of the current phase. -
limits: one entry for each phase with a limit. A phase without a limit has no entry. -
limit.devices: the planned devices of the limiting burst. InSTEADYmode, the value is pings per second. -
Prometheus gauge
emulator_mqtt_ping_ramp_limit_devices: the limit of the current phase. The value is 0 until the load finds a limit. -
Warning in the log:
MQTT ping limit phase=<p> devices=<n> burst=<b> at=<time>.
The emulator can also be the reason for a miss. These rules protect the result:
-
In
BURSTmode, the load does not fire a slot one interval late or more. The slot counts intotals.missedSlots. -
In
BURSTmode, the newest slot less than one interval late still fires. -
In
STEADYmode, the load skips a cycle two intervals late or more. Each skipped cycle counts intotals.missedSlots. -
In
STEADYmode, the load skips a device turn more than one interval late. -
A cycle with a skipped turn counts one missed slot.
-
A burst that starts more than half an interval late sets no limit.
-
A
STEADYsecond withstartDelayMsabove half an interval sets no limit either. -
The log shows a warning for such a burst:
MQTT ping late burst=<n> phase=<p> delayMs=<d> intervalMs=<i> (emulator behind, sets no limit). -
A burst wider than half an interval writes a width warning and sets no limit.
-
Then the emulator is the limit, not the broker.
-
A record with
stopped=truenever sets a limit. -
These events close an open record with
stopped=true:-
DELETE. -
A stop of the emulator.
-
A
POSTwith a new grid. -
The run end before the normal close of the record.
-
-
A
POSTcloses a single burst with a finished hand-off as a normal close. The record showsstopped=false.
Find the limit of a broker
Use this task to find the limit of the broker.
-
Set MTP Ping interval (sec) to 0 on the USP devices with the MQTT MTP.
-
Start the devices.
-
Send
POST /api/devices/mqtt-pingwith the ramp body from Start, status and stop.The answer is
202with the stateRUNNING. -
Send
GET /api/devices/mqtt-pingevery few seconds. -
Read
currentandrecent. -
Watch
unanswered,p99MsandstartDelayMs. -
Wait until
limitis notnull.limit.devicesis the burst size of the first burst with unanswered PINGREQ messages. -
Check the log for warnings.
A width warning or a late warning means the emulator is the limit. No warning does not prove a broker limit. See Emulator load in the answer times.
-
Send
DELETE /api/devices/mqtt-ping.The answer is
200with the final status.
Emulator load in the answer times
The answer time of a PINGREQ includes the work of the emulator MQTT client. This work covers the encryption, the write to the network and the read of the answer. A slow answer is not always a slow broker.
Use these steps to tell the two causes apart:
-
Run the same burst sizes against a local broker first. This is the baseline.
-
During the real run, watch the metric
process_cpu_usage. Its value is from 0 to 1 over all cores. -
If the value is above 0.9, add emulator instances and reduce the size of each burst.
Prometheus
Prometheus reads the metrics at http://<host>:8556/actuator/prometheus. Add the address to Percona Monitoring and Management (PMM) as an external exporter.
The names below are the Prometheus form. A dot in the meter name becomes an underscore. A counter name ends in total. Most names start with emulator_mqtt_ping. The drop counter starts with emulator_mqtt_connections_. The keep-alive metrics start with emulator_mqtt_keepalive_ping_. See Keep-alive ping metrics. Filter by emulator_mqtt_ to find all meters.
| Name | Meaning | Unit |
|---|---|---|
Counters since the start of the emulator |
||
|
PINGREQ messages handed to the MQTT client. |
Count |
|
PINGRESP messages received before the burst closed. |
Count |
|
PINGREQ messages without answer at the close of the burst. |
Count |
|
PINGREQ messages that failed before an answer. |
Count |
|
Failed hand-offs of PINGREQ messages to the MQTT client. |
Count |
|
Devices that sent no PINGREQ. The label |
Count |
|
Answers after the close of their burst. The counter keeps all runs. |
Count |
|
PINGREQ messages that failed after the close of their burst. The counter keeps all runs. |
Count |
|
Slots or cycles the emulator skipped. |
Count |
|
Closed bursts. In |
Count |
|
Dropped MQTT connections of all devices. |
Count |
Gauges of the last closed burst or second |
||
|
Devices selected. |
Devices |
|
PINGREQ messages sent. |
Count |
|
PINGRESP messages received. |
Count |
|
PINGREQ messages without answer at the close. |
Count |
|
Time between the first and the last PINGREQ. |
Milliseconds |
|
Time between the planned slot and the real start. |
Milliseconds |
|
Time until the last PINGRESP. The value is |
Milliseconds |
|
Real start of the burst. |
Milliseconds since 1 January 1970 |
|
Answer time. The label |
Milliseconds |
|
Devices that sent no PINGREQ. The label |
Devices |
|
Failed hand-offs of PINGREQ messages. |
Count |
|
PINGREQ messages that failed inside the burst. |
Count |
|
MQTT connections dropped from the open to the close of the burst. |
Connections |
Gauges of the current state |
||
|
1 if a load runs, otherwise 0. |
0 or 1 |
|
Devices with a PINGREQ still open after its burst closed. |
Devices |
|
Size of the open burst, or of the next burst. The value is never higher than the eligible devices. |
Devices |
|
Limit of the current phase. The value is 0 until the load finds a limit. |
Devices |
Histogram |
||
|
Answer time of every PINGRESP. Bucket limits in seconds: 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5. Higher limits: 10, 30, 60, 120. The top bucket is 120 seconds. |
Seconds |
The histogram emulator_mqtt_ping_response_seconds gives one p99 over all instances:
histogram_quantile(0.99, sum by (le) (rate(emulator_mqtt_ping_response_seconds_bucket[1m])))
The query returns seconds. All other times on this page are in milliseconds.
The histogram also records the answers that arrive after the close of their burst. The p99 of the histogram therefore shows the real tail of the broker, up to the top bucket of 120 seconds. A slower answer shows as 120 seconds. The values p50Ms, p99Ms and maxMs of a record leave these answers out.
A scrape every 5 to 15 seconds sees only the latest burst in the gauges. With 1-second bursts, Prometheus does not sample most bursts. The counters and the histogram lose nothing. For exact numbers for each burst, use the status call or the log.
Keep-alive ping metrics
A device with MTP Ping interval (sec) greater than 0 pings the broker by itself. The key is usp.mtp.ping_interval. The MQTT client of the device sends a PINGREQ after the keep-alive time without traffic. The emulator counts these PINGREQ messages and their answers. You need no load and no API call for these metrics.
The load does not change these metrics. A forced PINGREQ of the load does not count as a keep-alive ping.
| Name | Meaning | Unit |
|---|---|---|
Counters since the start of the emulator |
||
|
Keep-alive PINGREQ messages of the MQTT client. |
Count |
|
PINGRESP messages for keep-alive PINGREQ messages. |
Count |
|
Keep-alive PINGREQ messages without their own PINGRESP. The label |
Count |
Gauge of the current state |
||
|
Keep-alive PINGREQ messages with no answer yet. |
Count |
Histogram |
||
|
Answer time of every keep-alive PINGRESP. The time runs from the PINGREQ in the MQTT client to the PINGRESP. The bucket limits are the same as for |
Seconds |
Values of the label reason:
-
timeout: no PINGRESP came within the keep-alive time. The MQTT client closes the connection. Then the device connects again. -
connection_lost: the connection dropped for another reason during the wait for the PINGRESP. -
stopped: the emulator closed the connection during the wait for the PINGRESP. -
replaced: the MQTT client sent a new PINGREQ during the wait for the PINGRESP.
A stopped ping comes from a Stop of the emulator. A stopped ping also comes from a device restart by the USP controller: Reboot(), FactoryReset() or a firmware activation. After a restart, the device connects again.
A PINGRESP for a replaced PINGREQ often still comes. The MQTT client counts this PINGRESP as the answer to the new PINGREQ. The answer time of the new PINGREQ is then too short.
The counters add up: sent is answered plus all unanswered plus waiting. Each timeout and each connection_lost is also a drop in emulator_mqtt_connections_dropped_total.
Without other traffic, each device sends one PINGREQ per interval. The MQTT client skips a PINGREQ only if the device both sent and received other packets within the interval. Traffic in one direction does not replace a PINGREQ. With traffic in both directions, sent is lower than the number of devices multiplied by the run time and divided by the interval.
If the broker sets Server Keep Alive, the devices ping at the interval of the broker. The first PINGREQ can come at the interval of the device.
If Server Keep Alive is at most half of MTP Ping interval (sec), the MQTT client can close the connection after the first interval. Then the device connects again. The drop repeats after each connection. The drops count in emulator_mqtt_connections_dropped_total, but not in sent.
A device with MTP Ping interval (sec) 0 sometimes sends no PINGREQ at all, even with Server Keep Alive on the broker.
Keep-alive PINGREQ messages per second over all instances:
sum(rate(emulator_mqtt_keepalive_ping_sent_total[1m]))
The p99 of the answer time over all instances, in seconds:
histogram_quantile(0.99, sum by (le) (rate(emulator_mqtt_keepalive_ping_response_seconds_bucket[1m])))
Log
The logger com.friendly.emulator.gui.load writes these lines:
-
One
INFOline for each closed burst or second, in the key=value form. Example:MQTT ping burst=12 phase=1 step=30000 … dropped=0 stopped=false. The keystoppedcomes last. -
One
INFOline at each run start. A new phase writes the line again:MQTT ping run started phase=…. -
One
INFOline at the run end. -
One
WARNline when the load finds a limit. -
One
WARNline for a late burst. -
One
WARNline for a wide burst.
The width warning has this form:
MQTT ping width burst=<n> phase=<p> widthMs=<w> intervalMs=<i> (more than half the interval: the emulator is the limit)
The emulator writes no line for each PINGREQ.
Capacity
This is an estimate from a measurement on a test server. One PINGREQ needs at most about 0.13 ms of central processing unit (CPU) time in the emulator. A burst of 50,000 PINGREQ needs at most about 6.5 CPU seconds. For 100,000 PINGREQ per second, you need at most about 13 CPU cores in total across the instances.
The test server has 16 virtual CPU cores. Each instance has 50,000 devices and sends about 830 PINGREQ per second. These PINGREQ come from the normal keep-alive of the devices. The measurement does not include forced PINGREQ.
For developers
-
The emulator exposes only
prometheusandhealthat/actuator. -
The load starts no thread until the first
POST. -
One scheduler thread wakes about 20 ms before a slot.
-
In
BURSTmode, the scheduler sorts the list of devices about 20 ms before the slot. -
The engine does not sort the list.
-
In
STEADYmode, the scheduler reads the list of devices every 10 seconds. -
In
STEADYmode, the scheduler wakes once for each 10 ms tick and sends all due PINGREQ messages as one batch. -
The send threads hand the PINGREQ messages to the Paho client.
-
"Sent" means handed to Paho. The
widthMsvalue is a lower bound of the time on the wire. -
The classes are in the package
com.friendly.emulator.gui.load. The controller isMqttPingLoadController. -
The design is in
docs/superpowers/specs/2026-11-03-mqtt-ping-load-design.md.