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

POST

/api/devices/mqtt-ping

202 with the status. If a load runs, the call starts a new phase.

GET

/api/devices/mqtt-ping

200 with the status. The state is IDLE before the first run.

DELETE

/api/devices/mqtt-ping

200 with the final status. If no load runs, the call also answers 200 with IDLE.

The status has one of these states:

State Meaning

IDLE

No load runs. After a run ends, the status keeps the values of the run until the next run starts.

SCHEDULED

The first slot of the current grid has not come yet. A POST with a future startAt gives this state.

RUNNING

The first slot has come. A run without intervalMs stays RUNNING until endsAt.

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

mode

BURST, STEADY

BURST

BURST: each slot sends one PINGREQ from every selected device. STEADY: the devices send their PINGREQ spread evenly over the interval.

devices

1 to 1,000,000

All eligible devices

Number of devices for the load. If you give ramp, the emulator ignores this field.

intervalMs

100 to 3,600,000

None

Time between two slots in milliseconds. BURST without intervalMs sends one burst. STEADY needs the field.

durationSec

1 to 86,400

300

Run time in seconds.

startAt

Time in Coordinated Universal Time (UTC), for example 2026-11-10T10:00:00Z

Now

Start time on the wall clock. The time is at most 24 hours ahead. A time in the past works only with intervalMs.

ramp

Object with from, step, burstsPerStep, to

None

Growing burst size. Use ramp with BURST and intervalMs only. Each field is at least 1. from is at most to, and to is at most 1,000,000.

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 startAt plus a multiple of intervalMs.

  • The slots follow the wall clock. Instances with the same startAt and intervalMs stay aligned.

  • A run ends at endsAt: the first slot of the phase plus durationSec.

  • A run without intervalMs sends one burst. DELETE ends the run earlier.

  • A new POST while the load runs starts a new phase.

  • If mode and intervalMs stay the same, the new phase continues the slot grid. Omit startAt or keep its value.

  • The continued grid starts the new phase at its next slot.

  • A change of mode, intervalMs or startAt closes 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 POST with {"devices": 2000} drops intervalMs. 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 k has min(from + k / burstsPerStep * step, to) devices. The division is a whole-number division.

  • After to the size stays at to.

  • If the POST has a startAt, the count k is the number of slots since startAt.

  • A POST after startAt joins the ramp at the step of the slots since startAt.

  • The same startAt in a repeated POST keeps the count.

  • A new ramp then continues at the step for the time since startAt.

  • A new startAt restarts the count at 0.

  • A POST without startAt counts k from the first slot of its phase, starting at 0.

  • In STEADY mode, the status gives one record for each wall-clock second.

  • In STEADY mode, the emulator sends in ticks of 10 ms.

  • A PINGREQ in STEADY mode can leave up to 10 ms after its planned time.

  • In BURST mode, 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 POST joins the next burst.

  • In STEADY mode, 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 mode other than BURST or STEADY.

  • An invalid startAt. Use the form 2026-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, phase

State of the load, and number of the current phase. The phase is 0 before the first run.

parameters

The parameters of the current phase, with the defaults filled in.

eligibleDevices

Number of started USP MQTT devices with keep-alive 0.

waitingDevices

Number of devices with a PINGREQ still open after its burst closed.

nextSlot, endsAt

Time of the next slot and the end of the run. If no load runs, both are null.

currentStepDevices

Size of the open burst, or of the next burst. The value is never higher than eligibleDevices, also between two bursts.

limit, limits

The limit of the current phase, and the limits of all phases. See The limit.

current

The open burst or second, with the numbers so far.

recent

The last 200 closed bursts or seconds. The newest record comes first.

totals

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

kind, number, phase

Type of the record (burst or second), its number and its phase.

stepDevices, planned

Burst size from the ramp formula, and devices selected. planned counts started USP MQTT devices with any keep-alive. Devices with keep-alive above 0 show in skippedKeepAlive.

plannedAt, startedAt

Planned time of the slot, and real start.

startDelayMs

Time between the planned slot and the real start. In STEADY mode, a record is a second. Then the value is the largest delay of the PINGREQ messages sent in that second, in milliseconds. The value is 0 if all were on time.

sent

PINGREQ messages handed to the MQTT client. If DELETE, a stop of the emulator, the run end or a new grid closes the burst, the hand-off stops. The devices not yet reached get no PINGREQ and no count.

widthMs

Time between the first and the last PINGREQ of the burst.

answered

PINGRESP messages received before the burst closed.

unanswered

sent minus answered minus failed. The value is final in a closed record. In current, the value is the count so far.

failed

PINGREQ messages with no PINGRESP after a dropped connection. A reconnect or a stop of the connector gives the same result.

sendFailed

Failed hand-offs of PINGREQ messages to the MQTT client.

droppedConnections

Dropped MQTT connections during the burst.

allAnsweredMs

Time until the last PINGRESP. If a PINGREQ stays unanswered at the close, or if no PINGRESP came back, the value is null.

p50Ms, p99Ms, maxMs

Answer time in milliseconds: the 50th percentile, the 99th percentile and the maximum. The values cover the answers before the close. See below.

skippedNotConnected, skippedWaiting, skippedKeepAlive

Devices that sent no PINGREQ, with the reason.

stopped

true if DELETE, a stop of the emulator, a POST with a new grid, or the run end closes the record before its normal close. A POST closes a finished single burst as a normal close, so the record shows stopped=false.

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 shows stopped=true.

  • A POST changes mode, intervalMs or startAt. The record shows stopped=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.

  • lateResponses and lateFailures count 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. In STEADY mode, 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 BURST mode, the load does not fire a slot one interval late or more. The slot counts in totals.missedSlots.

  • In BURST mode, the newest slot less than one interval late still fires.

  • In STEADY mode, the load skips a cycle two intervals late or more. Each skipped cycle counts in totals.missedSlots.

  • In STEADY mode, 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 STEADY second with startDelayMs above 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=true never sets a limit.

  • These events close an open record with stopped=true:

    • DELETE.

    • A stop of the emulator.

    • A POST with a new grid.

    • The run end before the normal close of the record.

  • A POST closes a single burst with a finished hand-off as a normal close. The record shows stopped=false.

Find the limit of a broker

Use this task to find the limit of the broker.

  1. Set MTP Ping interval (sec) to 0 on the USP devices with the MQTT MTP.

  2. Start the devices.

  3. Send POST /api/devices/mqtt-ping with the ramp body from Start, status and stop.

    The answer is 202 with the state RUNNING.

  4. Send GET /api/devices/mqtt-ping every few seconds.

  5. Read current and recent.

  6. Watch unanswered, p99Ms and startDelayMs.

  7. Wait until limit is not null.

    limit.devices is the burst size of the first burst with unanswered PINGREQ messages.

  8. 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.

  9. Send DELETE /api/devices/mqtt-ping.

    The answer is 200 with 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:

  1. Run the same burst sizes against a local broker first. This is the baseline.

  2. During the real run, watch the metric process_cpu_usage. Its value is from 0 to 1 over all cores.

  3. 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

emulator_mqtt_ping_sent_total

PINGREQ messages handed to the MQTT client.

Count

emulator_mqtt_ping_answered_total

PINGRESP messages received before the burst closed.

Count

emulator_mqtt_ping_unanswered_total

PINGREQ messages without answer at the close of the burst.

Count

emulator_mqtt_ping_failed_total

PINGREQ messages that failed before an answer.

Count

emulator_mqtt_ping_send_failed_total

Failed hand-offs of PINGREQ messages to the MQTT client.

Count

emulator_mqtt_ping_skipped_total

Devices that sent no PINGREQ. The label reason is not_connected, waiting or keep_alive.

Count

emulator_mqtt_ping_late_responses_total

Answers after the close of their burst. The counter keeps all runs.

Count

emulator_mqtt_ping_late_failures_total

PINGREQ messages that failed after the close of their burst. The counter keeps all runs.

Count

emulator_mqtt_ping_missed_slots_total

Slots or cycles the emulator skipped.

Count

emulator_mqtt_ping_bursts_total

Closed bursts. In STEADY mode, the counter counts closed seconds.

Count

emulator_mqtt_connections_dropped_total

Dropped MQTT connections of all devices.

Count

Gauges of the last closed burst or second

emulator_mqtt_ping_last_planned

Devices selected.

Devices

emulator_mqtt_ping_last_sent

PINGREQ messages sent.

Count

emulator_mqtt_ping_last_answered

PINGRESP messages received.

Count

emulator_mqtt_ping_last_unanswered

PINGREQ messages without answer at the close.

Count

emulator_mqtt_ping_last_width_ms

Time between the first and the last PINGREQ.

Milliseconds

emulator_mqtt_ping_last_start_delay_ms

Time between the planned slot and the real start.

Milliseconds

emulator_mqtt_ping_last_all_answered_ms

Time until the last PINGRESP. The value is NaN if not all PINGREQ messages have an answer.

Milliseconds

emulator_mqtt_ping_last_started_timestamp_ms

Real start of the burst.

Milliseconds since 1 January 1970

emulator_mqtt_ping_last_response_ms

Answer time. The label quantile is 0.5, 0.99 or 1. The value 1 is the maximum.

Milliseconds

emulator_mqtt_ping_last_skipped

Devices that sent no PINGREQ. The label reason is not_connected, waiting or keep_alive.

Devices

emulator_mqtt_ping_last_send_failed

Failed hand-offs of PINGREQ messages.

Count

emulator_mqtt_ping_last_failed

PINGREQ messages that failed inside the burst.

Count

emulator_mqtt_ping_last_dropped_connections

MQTT connections dropped from the open to the close of the burst.

Connections

Gauges of the current state

emulator_mqtt_ping_running

1 if a load runs, otherwise 0.

0 or 1

emulator_mqtt_ping_waiting_devices

Devices with a PINGREQ still open after its burst closed.

Devices

emulator_mqtt_ping_step_devices

Size of the open burst, or of the next burst. The value is never higher than the eligible devices.

Devices

emulator_mqtt_ping_ramp_limit_devices

Limit of the current phase. The value is 0 until the load finds a limit.

Devices

Histogram

emulator_mqtt_ping_response_seconds

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

emulator_mqtt_keepalive_ping_sent_total

Keep-alive PINGREQ messages of the MQTT client.

Count

emulator_mqtt_keepalive_ping_answered_total

PINGRESP messages for keep-alive PINGREQ messages.

Count

emulator_mqtt_keepalive_ping_unanswered_total

Keep-alive PINGREQ messages without their own PINGRESP. The label reason gives the cause.

Count

Gauge of the current state

emulator_mqtt_keepalive_ping_waiting

Keep-alive PINGREQ messages with no answer yet.

Count

Histogram

emulator_mqtt_keepalive_ping_response_seconds

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 emulator_mqtt_ping_response_seconds.

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 INFO line 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 key stopped comes last.

  • One INFO line at each run start. A new phase writes the line again: MQTT ping run started phase=…​.

  • One INFO line at the run end.

  • One WARN line when the load finds a limit.

  • One WARN line for a late burst.

  • One WARN line 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 prometheus and health at /actuator.

  • The load starts no thread until the first POST.

  • One scheduler thread wakes about 20 ms before a slot.

  • In BURST mode, the scheduler sorts the list of devices about 20 ms before the slot.

  • The engine does not sort the list.

  • In STEADY mode, the scheduler reads the list of devices every 10 seconds.

  • In STEADY mode, 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 widthMs value is a lower bound of the time on the wire.

  • The classes are in the package com.friendly.emulator.gui.load. The controller is MqttPingLoadController.

  • The design is in docs/superpowers/specs/2026-11-03-mqtt-ping-load-design.md.