Skip to content
BoKSA

MQTT Ingest Performance Benchmark

MQTT Ingest Performance Benchmark

Picture the Learning Group city Raspberry Pi in the HvA server room (6th floor WBH). Today a handful of hubs publish a reading every few seconds and the back-end keeps up without effort. Now imagine the city grows: every tile gets more sensors, the traffic lights report every state change, and a classmate's simulator spins up two hundred virtual hubs. Does the back-end still store every message? How long does it take before a reading is in the database? At what message rate does the Pi start to fall behind, and what happens then: does the ingest service queue, drop, or crash? And does the answer change when the data goes into a relational database instead of a time series database?

Until now each city chose one type of database for its sensor data, often on gut feeling. In this challenge you replace that feeling with measurements. You make the city's ingest path work with both a relational database (for example PostgreSQL or MariaDB) and a time series database (for example InfluxDB, TimescaleDB, or QuestDB). You then load test the full chain, MQTT broker → ingest service → database, with a test client you select or build (for example JMeter with an MQTT plugin). Part 1 measures with a single-threaded client to find a clean baseline. Part 2 measures with a multi-threaded client and then several hosts publishing at the same time, a controlled, DDoS-like load on your own city Pi, to find where and how the system breaks. You work through research, advice, design, and realisation for your Sprint 3-4 Learning Goal. Follow the city Requirements. Evidence is individual, even though the results serve the whole Learning Group.

Your Learning Goal title in Portflow

Use: Sprint 3-4 - Learning Goal - MQTT Ingest Performance Benchmark (adjust the sprint number if needed). See the Learning Goal page for the Portflow template.

Illustration

The animation shows the two parts of the benchmark against the same chain on the city Pi. In Part 1 one single-threaded client publishes messages one after another; the ingest service keeps up and the measured latency stays low. In Part 2 several hosts with many threads publish at the same time. Messages pile up in front of the ingest service, latency climbs, and you find the system's limit. Each part is run against both databases. The animation is illustrative: which database holds up best on the city Pi is what your measurements must show.

Challenge

Your Learning Group needs to know how much MQTT traffic the city back-end can store, how fast, and with which database. The city's ingest service subscribes to the MQTT broker, turns each message into a normalised record with metadata (as the city Requirements demand), and writes it to a database. You make that ingest path work with two storage back-ends: one relational database and one time series database, both running in Docker on the city Pi, both storing the same data model. You select or build a load-testing tool that publishes realistic city messages, and you run a reproducible benchmark in two parts:

  • Part 1 – Single-threaded client. One client, one connection, one thread. You step up the publish rate until the chain no longer keeps up. This gives a clean baseline per database: maximum sustained throughput, end-to-end latency, and resource use on the Pi.
  • Part 2 – Multi-threaded and multi-host client. Many concurrent virtual hubs, first from one host with many threads, then from several hosts at once (for example distributed JMeter with remote workers, or several laptops running the same script). You find the breaking point per database and you describe how the system fails: growing backlog, dropped messages, broker disconnects, memory exhaustion, or a crashed container.

You will deliver a working dual-database ingest path, a reusable benchmark setup, measured results, and the documents that justify and explain them. Work in this order:

  1. Understand the problem. What load does the city produce today, and what is a realistic "busy city" scenario? Count the hubs, topics, message sizes, and publish intervals. Define what "keeping up" means, for example: "every published message is stored (0 % loss) and the p95 end-to-end latency stays below 1 s for 5 minutes." Define the metrics you will report and where each one is measured.
  2. Research. Compare realistic options for: which relational and which time series database (and in which configuration) fit the city data and the Pi's ARM64 CPU and memory; which load-testing tool can publish MQTT at a controlled rate, with many threads, and from several hosts (JMeter with an MQTT plugin, Locust with paho-mqtt, k6 with an MQTT extension, emqtt-bench, or your own client); and how to measure end-to-end latency, throughput, and loss correctly (timestamps in the payload, clock synchronisation between hosts, warm-up, repetitions). Keep it short: enough to choose and to measure fairly, not a survey of every database. Cite sources for decisions.
  3. Advise. Recommend one test tool and one benchmark method. After the measurements, advise the Learning Group which database the city should use for its sensor data, and why, based on your numbers, not on vendor marketing. State the limits of your conclusion (one Pi, one data model, one ingest implementation). Hosting on the city Raspberry Pi is already decided.
  4. Design. Specify the data model in both databases, the ingest service's storage abstraction (how you switch between the two back-ends), the message format, the test scenarios (load profile, threads, hosts, duration, QoS, payload), the metrics and how each is collected, and the test environment (versions, hardware, network, clock sync). Write it so someone else could rerun your benchmark and get comparable numbers.
  5. Realise. Build in small steps: the second database next to the first, then the switchable ingest path, then the single-threaded test, then the multi-threaded test, then the multi-host test. Commit the code, the test plans or scripts, the Compose files, and the raw results to the city GitLab project on main. Present the results with clear charts.

Minimum scope (Sprint 3–4)

Your contribution must include:

  • Two databases, both running as services in the city's shared Docker Compose stack on the city Pi:
    • one relational database (for example PostgreSQL or MariaDB)
    • one time series database (for example InfluxDB, QuestDB, or TimescaleDB). If you choose TimescaleDB on top of PostgreSQL, you compare it against a plain PostgreSQL table and you explain in your research why that is still a fair comparison.
    • both store the same readings with the same metadata (timestamp, device, topic, location, and similar), each in a schema that is idiomatic for that database (normalised tables for relational; measurements, tags, and fields, or hypertables, for time series)
  • The city's ingest service (in the shared back-end, not a private demo) can write to either database, chosen by configuration (for example an environment variable), without code changes. If the shared back-end is not ready yet, build a minimal ingest service in the city project and keep it compatible. Do not wait for classmates.
  • A load-testing tool that you select or build, and justify in your research. It must:
    • publish realistic city messages (agreed topic structure and payload format) to the city broker
    • control the publish rate and the number of concurrent clients/threads
    • put a unique message id and a send timestamp in every message, so loss and latency can be computed at the database side
    • be configured from files committed to the repo (for example a JMeter .jmx test plan, a Locust file, or a script with a config file), so anyone can rerun it
  • Part 1 – single-threaded benchmark, run against both databases:
    • one client, one connection, one thread
    • at least four load levels (stepped publish rates), each held long enough to reach a steady state (for example 2–5 minutes after a warm-up)
    • at least three repetitions per load level and database, with the database reset (or in a known state) before each run
    • report per run: sent, stored, lost messages; throughput (stored messages per second); end-to-end latency (p50, p95, p99, max); and CPU, memory, and disk I/O of the database and the ingest container on the Pi
    • the maximum sustainable throughput per database for a single client, by your own "keeping up" definition
  • Part 2 – multi-threaded and multi-host benchmark, run against both databases:
    • a multi-threaded run from one host with many concurrent clients (for example 10, 50, 100, 250 virtual hubs)
    • a multi-host run with at least two (preferably three or more) separate machines publishing at the same time, coordinated so the load starts and stops together (for example distributed JMeter with a controller and remote workers, or a script started on each host at the same agreed time)
    • a ramp-up test that keeps increasing the load until the chain no longer keeps up, and a short spike test (sudden jump in load) that shows how the system recovers
    • the breaking point per database and a description of the failure mode (what broke first: broker, ingest service, database, disk, network, or the client itself)
    • clock synchronisation between hosts (for example NTP/chrony) is checked and documented, or you explain how your latency measurement avoids cross-host clock errors
  • Results as a benchmark report with charts: throughput vs offered load, latency percentiles vs offered load, message loss, and resource use, for both databases side by side. Raw data (CSV/JTL/exports) and the scripts that produced the charts are in the repo.
  • A short advice to the Learning Group: which database the city should use for its sensor data, under which conditions, and what the expected safe load of the city Pi is.
  • Decisions, test method, results, and the "how to rerun the benchmark" how-to in English Markdown (city MkDocs / repo), with references.

If you have time, add one or more of:

  • Batching and write strategies: compare one insert per message with batched writes (for example 100 rows or 1 s per batch, or the database's line protocol / COPY), and show the effect on throughput and latency.
  • QoS comparison: QoS 0 vs QoS 1 (and 2) and the effect on throughput and loss.
  • Read under write load: measure the latency of a typical dashboard query (for example "average temperature per tile over the last hour") while the ingest test is running.
  • Storage footprint: disk usage per million readings in both databases, with and without compression or retention policies.
  • Back-pressure in the ingest service: a bounded internal queue, a batch writer, or several worker threads, and a before/after measurement.
  • Live monitoring during the tests (for example Prometheus + Grafana, cAdvisor, or the databases' own metrics endpoints) so you see where the bottleneck appears in real time.
  • Benchmark in CI: a small, short smoke benchmark that runs in the pipeline and warns when ingest performance drops after a change.

Out of scope for this challenge

These are not part of this challenge:

  • Load tests against anything other than your own city stack: not against school servers, other cities' Pis, public brokers, or cloud services.
  • Real attacks: spoofed addresses, botnets, amplification, or bypassing network limits. The multi-host test is a controlled load test with agreed machines, not a DDoS tool.
  • Choosing a third or fourth database "for completeness". Two databases, measured well, are the task.
  • Clustering, sharding, replication, or moving the database off the Pi to make the numbers look better.
  • Tuning the broker or the operating system kernel in depth. Document defaults you change; do not make tuning the project.
  • Rewriting the city's dashboard or features. You deliver the dual storage path, the benchmark, and the advice.
  • Testing on your laptop instead of the Pi. Local runs are fine for developing the tests; the reported numbers come from the city Pi.

Demo and safety context

Treat the load tests as experiments on shared lab infrastructure:

  • Agree a test window. A Part 2 run can make the city Pi unusable for classmates. Plan the runs with your Learning Group and coach, announce them, and keep them short.
  • Only your own target. All load goes to the city Pi's broker. Never point the test tool at another host. Hard-code or validate the target in your config so a typo cannot hit a different machine.
  • Stay inside the network rules. Multi-host tests on the school network must follow the HvA network rules. Discuss with your coach before you run them; if needed, run Part 2 on a separate switch or router with the Pi and the test hosts.
  • Have a stop button. Every test has a maximum duration and a documented way to stop it immediately on all hosts. Know how to restart the city stack if a test brings it down.
  • Do not lose city data. Benchmark data goes into separate databases, schemas, or buckets, or into a stack that is cleaned before and after the test. Real city readings are not deleted or overwritten.
  • Default to red. If a test makes the dashboard stop updating, the city's existing fail-state must show that; a performance problem must not look like a quiet city.
  • Clear demo script. Anyone in your Learning Group can show: "start the single-threaded test against the relational database → live throughput and latency", "switch the ingest service to the time series database by configuration only → same test, compared results", "start the multi-host test → backlog and latency rise; show where the limit is", and "stop all hosts → the system recovers (or show and explain why it does not)".

Starting points

Use these concrete first steps early in Sprint 3:

  1. Read the city Requirements and agree your challenge with the Learning Group (no duplicate challenges). If someone works on the City Sensor Dashboard or the Quality-Gated Deployment Pipeline, agree who owns the ingest service, the database services, and the Compose file.
  2. Write "keeping up" in one sentence. For example: "The chain keeps up when 100 % of messages are stored and p95 latency < 1 s over 5 minutes of constant load."
  3. Inventory the city. Count hubs, topics, payload sizes, and publish intervals today. Check the Pi: uname -m, memory, disk (SD card or SSD?), Docker and Compose versions, and which database the city uses now.
  4. Hello second database. Start the other database type next to the existing one in Compose on your laptop, create the schema, and insert one reading by hand.
  5. Hello load test. Install your candidate tool (for example JMeter with an MQTT plugin) and publish 1,000 messages with an id and a timestamp to a local broker. Count them in the database and compute latency with one SQL/Flux query.
  6. Try the Pi early. Run a small single-threaded test against the city Pi before you design the full benchmark. Note what you see in docker stats.
  7. Draft your research question. Example: Which of a relational and a time series database lets the city's Raspberry Pi back-end store the most MQTT sensor messages per second without loss and with acceptable latency, for a single client and for many concurrent clients?
  8. Create your Learning Goal in Portflow. Link the product deliverables you plan to submit. Follow Learning Goal.

Suggested sprint timeline

The Learning Group does not use Scrum, but you still follow the sprint rhythm of the Group Project: two sprints for this challenge (Sprint 3-4).

In the first sprint you focus on research and advice on the method, with both databases and a hello load test as experiments, and you finish Part 1. In the second sprint you focus on design and realisation of Part 2 (multi-threaded and multi-host), the analysis, and the final database advice.

Sprint Focus Outcome
3 Research & advise; Part 1 Research report; choice of databases and test tool; metrics and "keeping up" definition agreed with the Learning Group; both databases in the city Compose stack; switchable ingest path; single-threaded benchmark results for both databases
4 Design & realisation; Part 2 Design (data models, test scenarios, metrics, environment); multi-threaded and multi-host benchmark on the city Pi; breaking point and failure mode per database; benchmark report with charts; database advice; demo; Portflow evidence linked; reflection

Tools, frameworks, and hardware

Area Suggestions
Host City Raspberry Pi (server room, 6th floor WBH) running broker, ingest service, and both databases in Docker; note SD card vs SSD
Relational database PostgreSQL, MariaDB/MySQL: indexes on time and device, batch inserts, COPY
Time series database InfluxDB (line protocol, buckets, tags vs fields), TimescaleDB (hypertables), QuestDB (ILP): check ARM64 images and memory needs
Broker The city's broker, for example Mosquitto or EMQX; note its version and limits (max connections, in-flight messages, queue size)
Load testing Apache JMeter with an MQTT plugin (distributed mode: controller + remote workers); Locust + paho-mqtt (distributed workers); k6 with an MQTT extension; emqtt-bench; or your own client (Python paho, Node mqtt, Java Paho): justify in research
Measurement Message id + send timestamp in the payload, received_at/stored_at in the database; NTP/chrony for clock sync; docker stats, cAdvisor, Prometheus + Grafana, iostat/vmstat
Analysis Spreadsheet, Python (pandas + matplotlib), or Jupyter: percentiles, not only averages; charts committed with the raw data
Documentation English Markdown on city MkDocs + repo; cite sources for decisions

Profile knowledge worth revisiting:

Products

Your challenge evidence is a set of products: studio deliverables tied to learning outcomes. Submit them in Portflow and link them from your Learning Goal.

Analyse & Advise

Product What you deliver Template
Research Short analysis of which relational and which time series database, which load-testing tool, and which measurement method fit the city Pi; comparison with criteria (ARM64 support, memory, write model, multi-thread and multi-host support, effort); the benchmark method; the measured results of Part 1 and Part 2 Research product
Advice Decision document for the Learning Group: which database the city should use for sensor data and why (based on your measurements), the safe load of the city Pi, the conditions under which the advice changes, and what to improve first (for example batching). Pi hosting in the server room is given. Advisory report

Suggested titles for Portflow

  • Research: Relational vs time series storage for MQTT ingest on the city Pi
  • Advice: Database choice and safe ingest load for the city back-end

The advice report should build on the research report. Do not repeat the full result tables; refer to them and summarise. If the research grows past two databases and one test tool, it is too big. Cut it so you still measure.

Design & Realise

Deliver two products for Design & Realise. The Design Document sets the requirements. The Realisation Document proves each requirement is built. Copy those templates. The lists below are what this challenge adds inside those two documents. Submit both in Portflow and link them from your Learning Goal.

Product What you deliver Template
Design Document In the Design Document, cover: context, city Requirements link-in, architecture diagram of the measured chain, data model in both databases, storage abstraction in the ingest service, message format, "keeping up" definition, metrics and where they are measured, test scenarios for Part 1 and Part 2, test environment and clock sync, safety rules for the test window Design Document
Realisation Document Prove each requirement with both databases running in the city Compose stack on the city Raspberry Pi, the switchable ingest path on main, the committed test plans/scripts, and validation evidence: Part 1 and Part 2 results for both databases, the breaking point and failure mode, and the charts Realisation Document

Suggested titles for Portflow

  • Design: MQTT Ingest Performance Benchmark — data models, test scenarios, and metrics
  • Realisation: MQTT Ingest Performance Benchmark — dual-database ingest and measured results

Design Document — what to specify

Put the items below in your Design Document as requirements, or as a diagram a requirement points to. A peer should be able to rerun your benchmark without guessing:

  • Requirements. Both databases store the same readings with metadata; the ingest service switches database by configuration; the test tool controls rate and concurrency; every message carries an id and a send timestamp; results are reproducible.
  • Architecture. The measured chain (test hosts → network → broker → ingest service → database), where each component runs, and where each metric is captured.
  • Data model. The schema in both databases (tables, columns, indexes; or measurements, tags, fields, retention), with reasons for each choice.
  • Storage abstraction. How the ingest service hides the database (for example a repository interface with two implementations), and how batching, if any, works.
  • Message format. Topic structure, payload fields, payload size, QoS, retain flag.
  • Metrics. Definitions: offered load, throughput, loss, latency (from which timestamp to which), percentiles, resource use, and the "keeping up" threshold.
  • Test scenarios. Part 1: load levels, duration, warm-up, repetitions. Part 2: threads per host, number of hosts, ramp-up profile, spike, duration. The order of runs and how the database is reset between runs.
  • Test environment. Pi model, storage medium, OS, image versions, broker and database configuration, test hosts, network path, clock synchronisation.
  • Safety. Test window, target lock, stop procedure, data separation.
  • Test plan. For example: "1,000 messages at 10 msg/s → 1,000 stored, 0 lost", "switch DB_BACKEND → same test passes on the other database", "two hosts start within 1 s of each other", "clock offset between hosts < 10 ms", "stop command ends the load on all hosts within 5 s".

Realisation Document — what to prove

For each requirement, the Realisation Document needs proof it was engineered. For this challenge, include:

  • The Compose file with both databases, the schemas or init scripts, and the ingest service with the switchable storage on city GitLab main.
  • The test plans or scripts (for example .jmx files or Locust files) and their configuration, plus the analysis scripts or notebook.
  • Raw results (CSV/JTL/exports) for every reported run, and the charts made from them.
  • Part 1 results for both databases: tables and charts for throughput, latency percentiles, loss, and resource use per load level, with the spread over the repetitions.
  • Part 2 results for both databases: multi-threaded and multi-host runs, the ramp-up curve with the breaking point marked, the spike test, and the failure mode with evidence (logs, docker stats, broker statistics).
  • Proof of the multi-host setup: which machines, how they were coordinated, and the measured clock offset.
  • README: how to start the benchmark stack, how to switch the database, how to run Part 1 and Part 2, how to stop a test, and how to produce the charts.
  • Honest known limitations (for example "the test client saturated before the Pi did at 500 threads", "SD card I/O dominates the results", "latency across hosts includes up to 5 ms clock offset", "only three repetitions").

Quality indicators

When assessing this challenge as a whole, the following indicators are used. Use them as a self-check before you submit.

Problem fit

  • The question ("which database lets the city Pi store the most MQTT messages, how fast, single- and multi-client?") and the "keeping up" definition are described in plain language.
  • Scope is explicit: this challenge delivers a dual-database ingest path, a reproducible benchmark, and an advice for the city, not a database survey and not a stress tool for other systems.
  • The work respects the city Requirements (shared GitLab project on main, Docker on the city Pi, normalised data with metadata, documented decisions with references, no waiting on classmates).

Analyse & Advise products

  • Research and advice reports meet the research and advisory report quality indicators and are kept short enough that measuring still happens.
  • The choice of databases and test tool is supported by current documentation and a small experiment, not only opinion.
  • The advice states one clear recommendation for the city's database based on the measured results, and states when that recommendation would change.

Design

  • The Design Document meets that product's quality indicators: a short plan, testable requirements with sources, and at least one requirement that comes from the end user (the Learning Group as users of the back-end, or the visitor of the dashboard).
  • Both data models store the same information and are each idiomatic for their database.
  • Metrics are defined precisely (what is measured, from where to where, which percentiles), and the test scenarios make the two databases comparable (same messages, same load, same environment).
  • The test environment and safety rules are designed explicitly, including clock sync, reset between runs, and a stop procedure.

Realisation

  • The Realisation Document meets that product's quality indicators: every MUST requirement has proof it was built, including feedback and the end-user requirement.
  • Both databases run in the city Compose stack on the city Pi, and the ingest service switches between them by configuration only.
  • The test tool is committed to the repo, controls rate and concurrency, and can be rerun by a classmate from the README.
  • Part 1 (single-threaded) results exist for both databases at several load levels, with repetitions and the maximum sustainable throughput identified.
  • Part 2 results exist for both databases, from many threads and from at least two hosts at the same time, with the breaking point and the failure mode described and supported by evidence.
  • Loss and latency are computed per message (id and timestamps), not estimated from client-side counters only.
  • Results are presented with percentiles and charts, and the raw data is available.
  • Real city data was not lost or mixed with benchmark data.

Professional practice

  • Learning Goal in Portflow uses the correct naming format and links to all product evidence.
  • Test windows were agreed with the Learning Group and coach before Part 2 ran, and nobody else's system was targeted.
  • End-of-sprint reflection connects results to your learning question and to full-stack practice (data modelling, performance testing, measurement validity, capacity planning).
  • Documentation is in English Markdown and usable by other city students.
  • You did not block on classmates: a minimal ingest service, simulated hubs, or a local stack kept you moving.

Focus points

Watch out for these common issues while you work:

  • Measuring the client, not the server. A single JMeter or Python process on a laptop runs out of CPU long before a database does. Watch the client's CPU too. If the client is the bottleneck, that is a finding, and a reason for Part 2.
  • Publish rate ≠ storage rate. The client reports "10,000 msg/s sent", but the broker may drop QoS 0 messages and the ingest service may queue the rest. Only count what is in the database.
  • Averages hide the pain. An average latency of 50 ms can hide a p99 of 8 s. Report percentiles and max.
  • No warm-up, one run. The first minute is often different (caches, JIT, connection setup). Warm up, then measure, and repeat each run.
  • Unfair comparison. A tuned time series database with batching against a relational database with one INSERT and auto-commit per message measures your code, not the databases. Compare like with like, and report optimisations as a separate step.
  • Clock skew between hosts. Latency computed from a send timestamp on host A and a store timestamp on the Pi is wrong if the clocks differ. Synchronise and measure the offset.
  • Growing tables. Insert performance changes as a table grows. State how many rows were already in the database, and reset it between runs.
  • The SD card. On a Raspberry Pi, disk writes are often the real limit. Measure I/O and mention the storage medium.
  • Overloading the city by surprise. A Part 2 run without warning stops the dashboard for everyone. Agree the window first.
  • "DDoS" taken literally. The goal is a controlled, multi-host load test of your own system, not attack techniques. Keep the target locked to the city Pi.
  • Conclusions beyond the data. "Time series databases are faster" is not a finding. "On our Pi, with our schema and per-message inserts, X sustained 1,200 msg/s and Y 450 msg/s at p95 < 1 s" is.
  • Design–code drift. When you change the data model, scenarios, or metrics, update the Design Document first, then the proof in the Realisation Document.

Key points

  • Core task: make the city's ingest path work with a relational and a time series database, and measure both with a load-testing tool you select or build (for example JMeter).
  • Part 1: a single-threaded client at stepped load levels gives the baseline throughput, latency, and resource use per database.
  • Part 2: multi-threaded and multi-host clients push the city Pi to its breaking point; you describe how and where it fails.
  • Measure at the database: per-message id and timestamps for loss and latency; percentiles, repetitions, and charts.
  • Advise the Learning Group on the city's database based on your numbers, and state the limits of the conclusion.
  • Load only your own city Pi, in an agreed test window, with a stop button; real city data stays safe.
  • Deliver four products: research, advice, a design document, and a realisation document.
  • Work research → advice → design → realise; Sprint 3 emphasises research, advice, and Part 1; Sprint 4 emphasises design, realisation, and Part 2.
  • Link everything to your Learning Goal in Portflow and reflect at the end of Sprint 3-4.