Three protocols are the usual candidates when a device has to send small readings to a server. MQTT keeps one TCP connection open to a broker and publishes to topics. CoAP is HTTP’s shape (GET, POST, URIs, response codes) squeezed into UDP datagrams, made for constrained devices; it secures itself with DTLS, TLS’s datagram sibling, and lets a client observe a resource to be told about every change. AMQP is the enterprise message queue: RabbitMQ’s original AMQP 0-9-1 and the different, standardised AMQP 1.0, which RabbitMQ 4 speaks natively on the same port.
Each has a fire-and-forget mode and an acknowledged one, and the difference is where the interesting costs are. This benchmark measures all eight modes with the same 16-byte reading, on the same machine and the same emulated links: what goes over the wire, what the device’s radio has to send and receive, how long a connection takes to open, what packet loss does to delivery, and what it costs to stay connected. It follows the method of the MQTT vs HTTPS benchmark. Every message carries its sequence number and a payload derived from it, and every receiver checks every byte: 21,353,004 delivered messages, 0 corrupted, 0 duplicated.
Setup
Details
MQTT
Mosquitto 2.1.2 (eclipse-mosquitto:2), defaults apart from the TLS 1.3 listener, anonymous clients and set_tcp_nodelay true (the MQTT vs HTTPS benchmark measured what Nagle’s algorithm costs without it) · client: a minimal MQTT 5 client, QoS 0 and QoS 1
CoAP
Go 1.26 server and client on go-coap 3.5.9 over pion/dtls 3.1.15, DTLS 1.2 · POST publishes, GET with Observe (RFC 7641) subscribes · NON: non-confirmable, with No-Response (RFC 7967) so nothing comes back · CON: confirmable, answered by a 2.04 in the acknowledgement · notifications to the subscriber in the same mode · RFC 7252 timers: 2 s acknowledgement timeout, 4 retransmissions, one exchange in flight (NSTART = 1)
AMQP
RabbitMQ 4.4.0 (Erlang/OTP 29), one node, defaults apart from TLS 1.3 only · publishes to the amq.topic exchange, transient messages, classic queues · 0-9-1 (amqp091-go 1.16): without and with publisher confirms · 1.0 (go-amqp 1.7): pre-settled and unsettled transfers · SASL ANONYMOUS on both
Security
TCP protocols: TLS 1.3, TLS_AES_128_GCM_SHA256 · CoAP: DTLS 1.2, TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, the suite RFC 7252 mandates for certificates, with the cookie exchange · both: key exchange X25519, the same ECDSA P-256 certificate, full handshake every time (no resumption) · a second CoAP variant with a pre-shared key, TLS_PSK_WITH_AES_128_CCM_8
Network
One network namespace, IPv4 loopback at a 1,500-byte MTU with offloads off, so packets have real sizes · packets counted per direction by firewall rules on the server ports · links emulated with tc netem: LAN (nothing added), 50 ms round trip, 200 ms round trip with 1 % and with 5 % random loss in each direction
CPU
AMD Ryzen AI Max+ 395 · cores 0–7 and their SMT siblings reserved for the benchmark · Mosquitto, RabbitMQ (one Erlang scheduler) and the CoAP server one core each, clients on four more
Method
Every cell is a fresh client process, run 5 times · reported value: median of the 5 run values, with min–max · p99: each run’s 99th percentile, median across runs · one warm-up message before every latency and throughput cell, and a wait for a quiet link before every cell
The scoreboard
Eight headline measures from the sections below, each protocol's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 5 process runs; grey line: lowest to highest run. Each protocol in its acknowledged mode: MQTT QoS 1, CoAP CON, AMQP 0-9-1 with publisher confirms, AMQP 1.0 unsettled; the fire-and-forget modes are in the sections. CoAP CON on the LAN is a 60,000-message burst (see the throughput section); the idle hour is per protocol, with the same 60 s setting for all.Eight headline measures from the sections below, each protocol's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 5 process runs; grey line: lowest to highest run. Each protocol in its acknowledged mode: MQTT QoS 1, CoAP CON, AMQP 0-9-1 with publisher confirms, AMQP 1.0 unsettled; the fire-and-forget modes are in the sections. CoAP CON on the LAN is a 60,000-message burst (see the throughput section); the idle hour is per protocol, with the same 60 s setting for all.
Measure
MQTT QoS 1
CoAP CON
AMQP 0-9-1
AMQP 1.0
Bytes per message, both directions
192 B 192 B
172 B 172–262 B · 1.1×
257 B 257 B · 0.75×
229 B 229 B · 0.84×
New connection, 50 ms link
203 ms 202–203 ms
204 ms 202–204 ms · same
406 ms 405–410 ms · 0.50×
457 ms 455–460 ms · 0.44×
New connection, 200 ms + 5 % loss
803 ms 802–1,207 ms
804 ms 802–1,803 ms · same
1,608 ms 1,607–2,226 ms · 0.50×
1,809 ms 1,806–3,070 ms · 0.44×
Delivery, LAN
14 µs 14–24 µs
30 µs 28–38 µs · 0.47×
45 µs 44–45 µs · 0.31×
41 µs 39–43 µs · 0.34×
Delivery p99, 200 ms + 5 % loss
696 ms 622–1,048 ms
2,210 ms 2,209–4,208 ms · 0.31×
849 ms 661–1,011 ms · 0.82×
866 ms 633–2,045 ms · 0.80×
Messages/s, LAN
117,759 msg/s 116,908–118,137 msg/s
39,568 msg/s 34,518–40,082 msg/s · 0.34×
31,924 msg/s 31,599–31,994 msg/s · 0.27×
38,217 msg/s 38,087–38,453 msg/s · 0.32×
Messages/s, 50 ms link
397 msg/s 394–397 msg/s
20 msg/s 20 msg/s · 0.05×
397 msg/s 393–397 msg/s · same
347 msg/s 343–356 msg/s · 0.87×
Idle hour at a 60 s keep-alive
12.2 KB 12.2–13.1 KB
7.3 KB 7.3 KB · 1.7×
27.0 KB 25.9–27.0 KB · 0.45×
33.8 KB 33.8 KB · 0.36×
Median of 5 process runs, lowest to highest run beneath; bold: best in every run; after the range, the factor against MQTT QoS 1: above 1× better than MQTT QoS 1, below 1× worse, same: rounds to 1×.
Counting a measure only where every run agrees, against MQTT QoS 1: CoAP CON is better on 1 (up to 1.7× on idle hour at a 60 s keep-alive), worse on 4 (down to 0.05× on messages/s, 50 ms link) and ties on 3; AMQP 0-9-1 is never better: worse on 6 (down to 0.27× on messages/s, LAN) and ties on 2; AMQP 1.0 is never better: worse on 7 (down to 0.32× on messages/s, LAN) and ties on 1. The sections below take each measure in turn, with the fire-and-forget modes, the 1 % loss link, CoAP with a pre-shared key and the runs behind every median.
Each protocol's median against MQTT QoS 1's on the same measure, log scale; above 1× it is better than MQTT (fewer bytes, faster, more messages per second). Median of 5 process runs.Each protocol's median against MQTT QoS 1's on the same measure, log scale; above 1× it is better than MQTT (fewer bytes, faster, more messages per second). Median of 5 process runs.
One reading on the wire
On a connection that is already open, what does the device send for one 16-byte reading? Start with the fire-and-forget modes and the single packet each one sends:
The packet the device sends for one 16-byte reading on an open connection, fire-and-forget mode, as counted on the interface (median of 5 runs × 200 messages), divided by what each layer costs per packet: 52 B of IPv4 + TCP (with timestamps) or 28 B of IPv4 + UDP, 22 B per TLS 1.3 record, 29 B per DTLS 1.2 record with AES-128-CCM-8. Replies and TCP acknowledgements are in the next figure.The packet the device sends for one 16-byte reading on an open connection, fire-and-forget mode, as counted on the interface (median of 5 runs × 200 messages), divided by what each layer costs per packet: 52 B of IPv4 + TCP (with timestamps) or 28 B of IPv4 + UDP, 22 B per TLS 1.3 record, 29 B per DTLS 1.2 record with AES-128-CCM-8. Replies and TCP acknowledgements are in the next figure.
CoAP sends 106 B, MQTT 110 B. CoAP’s own framing is not the reason: with go-coap’s default 8-byte token, the path /sensors/42/temp as three Uri-Path options, a Content-Format and the No-Response option, its message is 33 bytes before the payload, against MQTT’s 20. DTLS framing is larger than TLS’s too: a 13-byte record header with the epoch and sequence number in it, and an 8-byte explicit nonce. What CoAP saves is the transport: UDP’s 8-byte header instead of TCP’s 32.
The bigger difference is what comes back. Counting both directions:
Median of 5 process runs × 200 messages, IP packets counted on the interface before and after, split by direction. Sent = device to server, received = server to device (replies, acknowledgements and TCP's ACKs). In each pair the first mode is fire-and-forget, the second waits for the server's acknowledgement. Grey line: lowest to highest run. In one of the 5 runs the CoAP received count is higher: the server was still notifying a subscriber from an earlier cell (a likely cause, not verified: its DTLS close was lost on the 5 % link), and the firewall counts everything the server sends; the device itself sent and received the same packets in every run.Median of 5 process runs × 200 messages, IP packets counted on the interface before and after, split by direction. Sent = device to server, received = server to device (replies, acknowledgements and TCP's ACKs). In each pair the first mode is fire-and-forget, the second waits for the server's acknowledgement. Grey line: lowest to highest run. In one of the 5 runs the CoAP received count is higher: the server was still notifying a subscriber from an earlier cell (a likely cause, not verified: its DTLS close was lost on the 5 % link), and the firewall counts everything the server sends; the device itself sent and received the same packets in every run.
Per 16-byte message
Sent
Received
Packets sent / received
MQTT QoS 0
110 B
52 B
1.00 / 1.00
MQTT QoS 1
113 B
79 B
1.01 / 1.00
CoAP NON
106 B
0 B
1.00 / 0.00
CoAP CON
103 B
69 B
1.00 / 1.00
AMQP 0-9-1
161 B
52 B
1.00 / 1.00
AMQP 0-9-1, confirms
162 B
95 B
1.01 / 1.00
AMQP 1.0, settled
130 B
38 B
1.00 / 0.72
AMQP 1.0, unsettled
130 B
99 B
1.02 / 1.01
Fire-and-forget over TCP is still two packets. TCP acknowledges every message the device sends; the device’s radio has to stay on to receive that ACK. MQTT QoS 0: 162 B in 2 packets. CoAP NON is the only mode that is one packet, out and done: 106 B.
An application acknowledgement is almost free over TCP. The broker’s PUBACK, publisher confirm or AMQP 1.0 disposition rides in the packet that would have carried TCP’s ACK anyway: MQTT QoS 1 costs 30 B more than QoS 0, AMQP 0-9-1 confirms 44 B, AMQP 1.0 unsettled 61 B.
Over UDP the acknowledgement is a packet of its own. CoAP CON: 172 B, an acknowledgement of 69 B coming back. Still the cheapest acknowledged mode, 20 B under MQTT QoS 1.
AMQP is the heaviest for small messages: 0-9-1 sends a method frame with the exchange and routing key, a content header and a body frame for every message (161 B sent); 1.0 packs it into one transfer frame with a delivery tag (130 B).
For a battery-powered radio the packet count matters more than the bytes. Waking up to transmit and staying awake to listen for a reply costs far more energy than the extra bytes in either packet. On that count CoAP NON is in a class of its own: one transmission, nothing to wait for. Every other mode, fire-and-forget or not, transmits once and then has to receive.
Opening a connection
From nothing to the first message acknowledged: the TCP handshake and TLS 1.3 for MQTT and AMQP, the DTLS 1.2 handshake for CoAP, then whatever the protocol needs before it may publish.
New connection, full handshake (no session resumption), then one 16-byte message until it is acknowledged (MQTT QoS 1, CoAP CON, AMQP 0-9-1 with publisher confirms, AMQP 1.0 unsettled). Median of 5 process runs × 5 connections per phase boundary. RTT = round trips at that link's delay. LAN numbers and bytes are in the table below.New connection, full handshake (no session resumption), then one 16-byte message until it is acknowledged (MQTT QoS 1, CoAP CON, AMQP 0-9-1 with publisher confirms, AMQP 1.0 unsettled). Median of 5 process runs × 5 connections per phase boundary. RTT = round trips at that link's delay. LAN numbers and bytes are in the table below.
New connection
LAN
50 ms
200 ms 1 % loss
200 ms 5 % loss
Bytes
Packets sent / received
MQTT, TLS 1.3
1.11 ms
203 ms
802 ms
803 ms
2,647 B
9 / 7
CoAP, DTLS 1.2 certificate
1.39 ms
204 ms
803 ms
804 ms
1,538 B
4 / 4
CoAP, DTLS 1.2 PSK
714 µs
203 ms
801 ms
802 ms
885 B
4 / 4
AMQP 0-9-1, TLS 1.3
3.19 ms
406 ms
1,605 ms
1,608 ms
3,981 B
13 / 11
AMQP 1.0, TLS 1.3
3.46 ms
457 ms
1,805 ms
1,809 ms
4,232 B
14 / 12
The two security handshakes, exactly as measured:
TLS 1.3 over TCP: 2 round trips (taken apart in the TLS handshake benchmarks). TCP’s SYN, SYN-ACK; then ClientHello with an X25519 key share, and the server’s whole answer (ServerHello, encrypted extensions, certificate, its signature, Finished) in one flight. The client can send data with its Finished. On the 50 ms link the handshake is done after 102 ms.
DTLS 1.2 with a certificate: 3 round trips, no TCP. ClientHello; HelloVerifyRequest with a cookie, so the server keeps no state for a client that cannot prove its address (a defence against spoofed-source floods); ClientHello again with the cookie; then ServerHello, certificate, signed key exchange and ServerHelloDone; then the client’s key exchange, ChangeCipherSpec and Finished, answered by the server’s. 153 ms on the 50 ms link, 1,538 B in all, with the first message.
DTLS 1.2 with a pre-shared key: the same 3 round trips, but no certificate and no key exchange: 885 B in all. The price is that there is no forward secrecy (anyone who later learns the key can decrypt recorded traffic) and a key to provision into every device.
After the handshake, the protocols differ by how many round trips they need before the first message counts:
CoAP: none. The first POST goes right after the handshake: 204 ms in total, 4 round trips.
MQTT: one, CONNECT and CONNACK, then the PUBLISH: 203 ms, also 4. One round trip fewer for the handshake, one more for the session: a tie.
AMQP 0-9-1: 5. Protocol header and connection.start, start-ok and tune, tune-ok/open and open-ok, channel.open, confirm.select, each waiting for its answer: 406 ms.
AMQP 1.0: 6. A SASL exchange, then the AMQP header, open, begin and attach, as the go-amqp client sends them one after another: 457 ms.
On the 200 ms link loss barely moves the medians: at 5 % they are 804 ms for CoAP, 803 ms for MQTT, 1,608 ms and 1,809 ms for AMQP, the same round trips as at 1 %; most of the 25 connections per mode lost nothing. The loss shows in the slowest connection of each mode: 3,812 ms for CoAP, 2,067 ms for MQTT, 4,142 ms and 6,295 ms for AMQP. The explanation, from the stacks’ timers rather than a measurement: a lost handshake packet costs about a second on both sides, because TCP waits 1 s before resending a lost SYN and pion/dtls resends a handshake flight after 1 s. The more round trips a protocol needs, the more chances it has to lose one.
Delivery latency, and what loss does to it
Once connected: how long from publishing until the subscriber has the message? Through the broker or the CoAP server, so every message crosses the link twice. One message at a time.
Median delivery
LAN
50 ms
200 ms 1 % loss
200 ms 5 % loss
MQTT QoS 0
11 µs
50.1 ms
200 ms p99 200 ms
200 ms p99 1,020 ms
MQTT QoS 1
14 µs
50.3 ms
200 ms p99 611 ms
200 ms p99 696 ms
CoAP NON
24 µs
50.2 ms
200 ms p99 201 ms
200 ms p99 201 ms
CoAP CON
30 µs
50.2 ms
200 ms p99 2,209 ms
200 ms p99 2,210 ms
AMQP 0-9-1
30 µs
50.2 ms
200 ms p99 605 ms
200 ms p99 1,031 ms
AMQP 0-9-1, confirms
45 µs
50.3 ms
200 ms p99 201 ms
201 ms p99 849 ms
AMQP 1.0, settled
31 µs
50.5 ms
201 ms p99 605 ms
200 ms p99 637 ms
AMQP 1.0, unsettled
41 µs
50.5 ms
201 ms p99 605 ms
201 ms p99 866 ms
CoAP CON, go-coap default tick
–
–
201 ms p99 4,565 ms
201 ms p99 5,224 ms
Without loss the protocols are indistinguishable once a connection is open: tens of microseconds on the LAN, one round trip on the 50 ms link (MQTT QoS 1 50.3 ms, CoAP CON 50.2 ms, AMQP 0-9-1 with confirms 50.3 ms). Acknowledgements do not delay delivery: every broker forwards a message before, or while, it acknowledges it.
Loss is where the transports part ways:
One 16-byte message at a time from the publisher until the subscriber has it, through the broker or CoAP server: two hops, each crossing the emulated link. Solid bar: median of 5 runs × 50 messages; lighter extension: each run's 99th percentile, median across runs. CoAP NON drops what is lost (lost share after the bar). Go-coap checks its retransmission timer every 4 s unless told otherwise; the 4 s tick row keeps that default, every other CoAP row checks every 10 ms. Grey line: lowest to highest run median.One 16-byte message at a time from the publisher until the subscriber has it, through the broker or CoAP server: two hops, each crossing the emulated link. Solid bar: median of 5 runs × 50 messages; lighter extension: each run's 99th percentile, median across runs. CoAP NON drops what is lost (lost share after the bar). Go-coap checks its retransmission timer every 4 s unless told otherwise; the 4 s tick row keeps that default, every other CoAP row checks every 10 ms. Grey line: lowest to highest run median.
TCP retransmits early, backs off, and delivers in order. A lost segment is resent after the retransmission timeout (Linux’s minimum is 200 ms plus the round trip, doubling if the resend is lost too; the timer itself was not observed here), and everything behind it on the connection waits. At 5 % loss the slowest 1 % of MQTT QoS 1 messages take 696 ms, AMQP 849 ms and 866 ms. Fire-and-forget over TCP is just as reliable: QoS 0, AMQP 0-9-1 without confirms and pre-settled AMQP 1.0 lost nothing, because TCP resends for them.
CoAP CON waits 2 seconds. RFC 7252 sets the acknowledgement timeout to 2–3 s, made for radios where a quick resend would only add to congestion. A lost CON message or its acknowledgement costs one timeout: 2,210 ms at the 99th percentile on the 5 % link, 2,209 ms at 1 %. In exchange, a loss delays only that one message, not the ones behind it.
CoAP NON loses what is lost. 3.2 % of messages at 1 % loss, 11 % at 5 %: each message crosses the link twice, publisher to server and server to subscriber, and either crossing can drop it. Nothing is retransmitted and nobody is told.
Check the library’s timer. Go-coap does not run its retransmission timer continuously; it checks for due retransmissions every 4 seconds by default. With that default a lost message waits up to 4 s longer than the protocol says: 5,224 ms at the 99th percentile on the 5 % link. Every other CoAP measurement here sets the check to 10 ms. Go-coap also resends at a fixed 2 s interval with no random factor, where the RFC asks for 2–3 s, doubling each time; with these loss rates a second retransmission was rare.
Throughput on one connection
How many messages per second can one connection deliver from a publisher to a subscriber? The publisher sends as fast as the mode allows, for 3 s on the LAN and 8 s on the 50 ms link. Acknowledged modes may have at most 20 messages unacknowledged: that is the receive maximum Mosquitto announces for MQTT QoS 1, and the same window is used for AMQP. CoAP CON may have one (NSTART = 1, as RFC 7252 says by default), and the CoAP server keeps one confirmable notification outstanding per subscriber, as RFC 7641’s congestion rules ask.
Publisher sending as fast as the mode allows for 8 s on the 50 ms link, 16-byte messages delivered to the subscriber per second, median of 5 runs. Acknowledged modes keep at most 20 messages in flight (Mosquitto's receive maximum; the same window for AMQP), CoAP CON one (NSTART = 1, RFC 7252's default). Log scale: each gridline is 10× the previous one. Grey line: lowest to highest run. Both links in the table below.Publisher sending as fast as the mode allows for 8 s on the 50 ms link, 16-byte messages delivered to the subscriber per second, median of 5 runs. Acknowledged modes keep at most 20 messages in flight (Mosquitto's receive maximum; the same window for AMQP), CoAP CON one (NSTART = 1, RFC 7252's default). Log scale: each gridline is 10× the previous one. Grey line: lowest to highest run. Both links in the table below.
Messages/s
LAN
50 ms
Lost LAN / 50 ms
MQTT QoS 0
223k 215k–231k
81k 77k–82k
0 / 18 %
MQTT QoS 1
118k 117k–118k
397 394–397
0
CoAP NON
111k 74k–111k
98k 66k–99k
55 % / 49 %
CoAP CON
40k 35k–40k · a 60,000-message burst, see below
20 20–20
0
AMQP 0-9-1
55k 54k–55k
51k 51k–52k
0
AMQP 0-9-1, confirms
32k 32k–32k
397 393–397
0
AMQP 1.0, settled
64k 61k–65k
3,171 3,164–3,191
0
AMQP 1.0, unsettled
38k 38k–38k
347 343–356
0
On the LAN this measures software: TLS or DTLS, the broker, the library. On the slow links it measures how many messages each mode allows in flight:
CoAP CON: one per round trip, 20 per second at 50 ms. Raising NSTART would help the publisher’s hop, but not the notification hop to the subscriber.
CoAP CON also runs out of message IDs. The Message ID is 16 bits, and RFC 7252 (§4.4) says the same ID must not be reused with the same peer within EXCHANGE_LIFETIME, 247 s at the RFC’s default timers (§4.8.2): at most 65,536 messages to one peer per 247 s, about 265 a second sustained. Go-coap does not enforce that. In the first attempts of this benchmark the LAN cell passed 65,536 messages within 3 s, the server took new messages for retransmissions of old ones (duplicate detection by Message ID) and answered from its cache, and the publisher hung. The LAN cell therefore stops at 60,000 messages, and its rate is that burst’s: 39,568 per second, which a conforming CoAP endpoint could not sustain.
MQTT QoS 1, AMQP with confirms, AMQP 1.0 unsettled: 20 per round trip, 397, 397 and 347 per second.
AMQP 1.0 pre-settled: 3,171. Pre-settled does not mean unlimited: AMQP 1.0 lets a sender transfer only as much as the receiving end has granted in link credit, and RabbitMQ grants it in small batches: about 159 messages per 50 ms round trip, if the rate is read as one credit batch per round trip (the credit frames themselves were not captured).
MQTT QoS 0 and AMQP 0-9-1 without confirms are limited only by TCP: 81,334 and 51,276 delivered per second. (The MQTT vs HTTPS benchmark measured 62,035 for QoS 0 on the same broker version with its own client build and a 10 s window; a one-connection rate depends on the client as much as on the broker.) AMQP 0-9-1 holds the publisher back when the queue cannot keep up (RabbitMQ’s credit flow, by its documentation; not measured here); Mosquitto does not, and (by its documented queue limits; the drops were counted, their place not traced) dropped what the subscriber’s queue could not hold.
CoAP NON has no window and no back-pressure at all: 98,488 delivered per second, and what was lost is simply gone (see Lost in the table; where it was dropped, most likely at the server’s socket, was not traced).
None of this matters for a sensor sending a reading a minute. It matters for a gateway forwarding a fleet over one uplink.
The cost of an idle hour
A device that has nothing to say still pays to stay connected.
Measured over 12 s per run (5 runs) with the keep-alive at 2 s (MQTT, CoAP: the client pings) or the heartbeat / idle timeout at 4 s (AMQP: both ends send at half of it), all headers and TCP acknowledgements included, then scaled to the same protocol setting of 60 s. Grey line: lowest to highest run.Measured over 12 s per run (5 runs) with the keep-alive at 2 s (MQTT, CoAP: the client pings) or the heartbeat / idle timeout at 4 s (AMQP: both ends send at half of it), all headers and TCP acknowledgements included, then scaled to the same protocol setting of 60 s. Grey line: lowest to highest run.
MQTT: one PINGREQ and PINGRESP per keep-alive interval, 204 B per exchange with TLS and TCP around it: 12.2 KB and 180 packets an hour at 60 s.
AMQP: a heartbeat setting of 60 s means each end sends a heartbeat when it has been silent for 30 s, so twice as many frames, in both directions: 27.0 KB (0-9-1) and 33.8 KB (1.0) an hour.
CoAP: UDP has no connection, and DTLS itself has no keep-alive. How long an idle session lives is the server’s choice: go-coap’s server closes one after 16 s with nothing received (this one was set to 10 minutes, because a NON subscriber sends nothing after registering), and a NAT between the two may forget the mapping within minutes. A CoAP ping, an empty confirmable message answered by a reset, refreshes both: 122 B per exchange, 7.3 KB an hour at 60 s. Where neither applies, an idle CoAP device costs nothing at all, and the alternative is cheap too: a full PSK handshake is 885 B.
What this does not show
Real radio. NB-IoT, LTE-M or LoRa modems pay for waking up and for staying awake after a transmission, not for bytes. Packet counts here are a proxy; the energy per packet depends on the radio’s timers, which no loopback test has.
NAT and carrier timeouts. Mobile networks drop idle UDP mappings faster than TCP ones, often within a minute or two. A CoAP device behind one has to send, or ping, more often than the 60 s used here, or re-handshake. DTLS 1.2 Connection ID (RFC 9146), which lets a session survive a changed address, was not used.
Real loss.netem drops packets independently at random. Real links lose in bursts, which hurts TCP’s in-order delivery more, and CoAP’s fixed timers less, than this test shows.
Other implementations. Go-coap’s retransmission timing is not RFC-exact (fixed 2 s, no random factor, a polling tick); libcoap or Californium would retransmit differently. Every number is one broker or library at its defaults, as listed in the setup table.
Certificate chains and resumption. One small ECDSA certificate and full handshakes. A public chain adds kilobytes to every new TLS or DTLS connection; session resumption removes most of them.
DTLS 1.3, CoAP over TCP, MQTT-SN, QUIC. Each changes some of these trade-offs. None was measured.
Brokers at scale. One node, one core each, one publisher. Clustering, persistence and fan-out are a different benchmark.
What the numbers say
Per message, CoAP NON is the cheapest by a margin: 106 B and one packet, against 162 B and two for MQTT QoS 0 and 213 B for AMQP 0-9-1. It is also the only mode that can lose a message without anyone knowing: 11 % at 5 % link loss.
Acknowledged, CoAP CON and MQTT QoS 1 are close, 172 B and 192 B, both two packets. Over TCP the acknowledgement is nearly free; over UDP it is a packet.
A new connection costs 4 round trips for CoAP and MQTT alike: DTLS 1.2 needs one more round trip than TCP plus TLS 1.3, MQTT spends it on CONNECT. AMQP needs 8 (0-9-1) or 9 (1.0) and about 4.0 KB. A PSK instead of a certificate cuts DTLS to 885 B.
Under loss, TCP starts resending after about 200 ms and backs off; CoAP CON waits 2 s, once per lost message: at the 99th percentile on the 5 % link, MQTT QoS 1 696 ms, AMQP 0-9-1 with confirms 849 ms, CoAP CON 2,210 ms. A library’s timer granularity can make CoAP’s 5,224 ms.
On a slow link, in-flight limits decide throughput: one message per round trip for CoAP CON, twenty for the acknowledged TCP modes.
Idle, CoAP owes nothing to the protocol, only to a NAT or a server that forgets sessions; MQTT spends 12.2 KB an hour at a 60 s keep-alive, AMQP 27.0–33.8 KB.
Reproduce it
The harness is one Go program (the CoAP server, and clients for all four protocols), two broker configuration files and a driver script. It builds one image, starts Mosquitto, RabbitMQ and the CoAP server in the client’s network namespace, and runs every cell as a fresh client process:
./certs.sh # throwaway CA and ECDSA P-256 certificate for localhostdocker build -t iotb . # Go 1.26 build, runs a self-test of the encoders and the checker./up.sh 4-7 1 2 3 # client cores, then Mosquitto, RabbitMQ and CoAP server coresdocker exec iot-net tc qdisc replace dev lo root netem delay 100ms loss 5% limit 100000 # the 5 % linkdocker exec iot-net ib run -test lat -kind coapcon -n 50 -settle 800ms
Each run prints one JSON line with every latency sample, the bytes and packets counted in each direction, and the check results: messages sent, received, corrupted, duplicated, missing and lost.