Work · Case file 10 · Public repository (three parts with CI; no licence chosen yet) · 2026
One detector, served three ways: a service, a C++ port and a ROS 2 node
4 min readJump to proofJump to limits
At a glance
- Result
- Under 2 CPUs the service saturates at 4 users and 24.0 requests a second; with keep-alive, one of 4 pods took every request. The C++ port is bit-identical but only 1.03 times as fast.
- Problem
- Nobody had measured what the detector serves per second, what a C++ build buys, or whether it can drive a robot.
- My role
- Solo, with Claude Code as the coding agent: the service, the C++ port, the ROS 2 nodes and every measurement. Teammates trained the model.Built by Zulfaqar Hafez with Claude Code as the coding agent, as each README says. The model is not mine: teammates trained it in a course project with Ultralytics YOLOv8 (AGPL-3.0) on a CC BY 4.0 dataset.
- Stack
- FastAPI and ONNX Runtime · Docker, Prometheus, Grafana · Kubernetes (kind) and k6 · C++17 · ROS 2 Jazzy and Nav2
Proof
- See it: the simulated camera in the Gazebo run
- See it: the ROS 2 graph from that run
- See it: C++ against Python, by stage
- See it: one model file, three ways to run it
- See it: the Compose stack's dashboard under load
- See it: the keep-alive comparison
- See it: the load test table
- Check it: the Gazebo run record
- Check it: C++ benchmark and parity results
- Check it: the C++ folder
- Check it: the service folder
- Check it: CI runs on GitHub Actions
- Check it: Kubernetes keep-alive results
- Check it: load test results
- Check it: repository
- Check it: the ROS 2 folder
- Check it: the numbers on this page (JSON)
The problem
The PPE detector on this site ran in a browser tab and a notebook. Nothing said how many requests it could serve, what a C++ build would buy, or whether it could steer a robot.
The idea. Wrap one model file, pinned by its SHA-256, three ways: an HTTP service, a C++ library and a ROS 2 node. Check each against the same reference images, measure each on one machine, and publish the numbers that went the wrong way too.
Fig. 01 · One model file, three ways to run it
One model file
ppe_yolov8s_320_int8dyn.onnx
SHA-256 d0a6c62f…0cbac2
Hash checked at docker build, on the file in the image, and at start (exit 3 on a mismatch)
service/HTTP service- FastAPI and ONNX Runtime
- Docker, Prometheus, Grafana
- Kubernetes on kind
Hash checked when CMake downloads the file
cpp/C++17 library and CLI- ONNX Runtime C++ API
- parity test against Python
- sanitizer-clean tests
Hash checked when the Docker build downloads the file
ros2/ROS 2 Jazzy nodes- lifecycle detector node
- patrol node, Nav2 goal
- Gazebo and replay
See it run
The detector's annotated output from the simulated TurtleBot3 camera during the recorded Gazebo run, 12 frames taken 1.5 s apart: the photo poster with its No-vest box at the start, the drive, and the view back at the poster from the inspection pose. Re-encoded from ros2/docs/evidence/gazebo/camera_clip.mp4.
How it works
Pin the model
Each part downloads ppe_yolov8s_320_int8dyn.onnx by URL and refuses it unless its SHA-256 matches. The service checks at docker build, in the image and at start, where a mismatch exits with code 3 so the container never becomes ready.
Serve it
service/ is FastAPI with one ONNX Runtime session shared by a worker pool sized from the container's CPU quota. An in-flight cap of 32 answers 503, a deadline 504, and SIGTERM drains open requests. Prometheus feeds a provisioned Grafana dashboard; k6 drives load at 1 and 2 CPU limits; kustomize manifests with an HPA run on a local kind cluster.
Port it to C++
cpp/ is a C++17 library and CLI on ONNX Runtime, with a port of Pillow's bilinear resize so the input tensor matches element for element. Tests run under clang, GCC, AddressSanitizer and UBSan; a benchmark times each stage against Python with matched settings.
Run it on a robot, in simulation
ros2/ is a ROS 2 Jazzy workspace. A C++ lifecycle node runs the detector on /camera/image_raw; a patrol node counts consecutive frames with a missing-PPE class and, at 3, sends a Nav2 NavigateToPose goal. It ran once in headless Gazebo with a TurtleBot3 facing a photo poster, and as a replay with a fake goal server for the tests.
What was hard
Deciding what counts as the result when a number goes the wrong way. The keep-alive run looked like working autoscaling: 4 pods. Counting requests per pod showed one pod doing all the work, because kube-proxy balances connections, not requests, and k6 connected while one pod existed. I kept that run beside one without keep-alive (30.2 against 12.2 req/s). The same rule held for the C++ port, which I expected to be much faster: the model call costs the same in both languages, so the gains are cold start and memory.
Limits. One 4 vCPU virtual machine, CPU only, with k6 sending synthetic load from the same host. Kubernetes means a local single-node kind cluster. The robot work is simulation, not hardware: one recorded Gazebo run in Nav2's small TurtleBot3 sandbox with a photo poster, and a replay of five still images against a fake goal server. The service has no authentication or TLS and is not deployed publicly. Accuracy was not re-measured: parity on five images shows the ports compute the same thing, not that the detections are right.
Evidence
- Source of every number
- Result files committed in ppe-serving at commit 983e4d0 (main, 13 Nov 2026).public/demos/ppe-serving/results.json, written by scripts/ppe-serving-results.mjs
- Service, 2-CPU limit
- 2 workers x 1 thread: 24.0 req/s at 4 users (p95 207 ms, the saturation point), 24.8 at 32 (p95 1,422 ms), no failures. The default peaked at 25.54 req/s against 17.70 for 1 worker x 2 threads, 44.3 percent more; the latter answers a lone user faster (p50 57 against 81 ms).service/results/loadtest/summary.md and summary.json
- Kubernetes keep-alive
- 8 users, 150 s, HPA 1 to 4 pods. Keep-alive on: 12.2 req/s, busiest pod 100.0 percent (1,832, 0, 0, 0). Off: 30.2 req/s, busiest pod 31.6 percent.service/results/k8s/hpa.md
- Shutdown under load
- 16 clients, then docker stop: all 16 open requests answered 200; exit 0 after 1.22 s.service/results/shutdown.json
- C++ against Python
- int8, 1 thread, 800 iterations, p50: end to end 81.0 against 83.7 ms (83.7 / 81.0 = 1.03); model call 72.2 in both; decode 6.23 against 9.32 ms. Cold start 156 against 271 ms; peak memory 57.9 against 91.7 MiB.cpp/results/bench.json; cpp/README.md, Results
- Parity
- C++ against Python: raw outputs bit-identical in 10 of 10 comparisons. Service against the site's reference: 26 detections, largest score gap 0.000492 (tolerance 0.001).cpp/results/parity.json; service/results/parity.json
- int8 against fp32
- C++ model call p50, 1 thread: int8 72.2 ms, fp32 49.8 ms. Smaller (44.63 / 11.37 = 3.93 times, in MB) but slower.cpp/README.md, int8 against fp32
- ROS 2 in Gazebo
- One recorded run: goal rejected while Nav2 started, retried, succeeded after 9.8 s of simulated time. Trigger: No-vest 0.673 for 3 frames; No-Helmet peaked at 0.39 (median 0.30) on the poster, against 0.627 on the photo.ros2/results/gazebo_run.json; ros2/README.md
- CI
- One workflow per part, all passing on 13 Nov 2026: 68 tests with the real model and a k6 latency gate (service), sanitizers and parity (C++), colcon test and a replay run (ROS 2).GitHub Actions runs; service/results/ci_local.log
Stack
- Python 3.13, FastAPI, uvicorn
- ONNX Runtime (Python and C++)
- Docker and Docker Compose
- Prometheus and Grafana
- k6
- Kubernetes on kind, kustomize, HPA
- C++17, CMake, doctest, stb_image
- ROS 2 Jazzy, rclcpp_lifecycle, Nav2
- Gazebo Harmonic
- GitHub Actions
