Chapter 15
Where is the unfinished work?
Measure a stated boundary and budget bytes, queues, fan-out and recovery.
Prerequisite: Choose connection and close policy. Course map →
The situation
A benchmark reports fast sends while receivers fall further behind. The benchmark counted sends that returned successfully. The receiver’s completed jobs need their own count.
Choose the measured boundary
Measure local admission, complete request/reply, handler work or a durable external effect explicitly. State transport, message sizes, frame count, serialization, concurrency, warmup, sample population and included setup costs. Validate answers before timing them.
The native benchmark in this repository measures completed inproc REQ/REP exchanges in one process after setup. It includes the stated send/receive loop, not a production network, multi-process topology or durable service. Browser Linux timing adds emulation and device-specific overhead.
Account for every unfinished population
Count requests presented to the service, accepted into its queue, started by workers, completed, rejected and discarded. State which step each counter records. Include retries, snapshots and repair traffic in offered load. A median among completed requests can conceal old requests that have not finished at all.
Apply size limits in bytes and frames as well as message-count HWM. Application arrays, peer queues, kernel buffers, pending-ID maps, caches and monitoring data can retain work independently. Moving the backlog to another layer does not eliminate it.
Measuring a service
Illustrative case.
Compare the send loop with a completed round trip. Which count requires a reply?
| Boundary | Useful evidence | Remaining question |
|---|---|---|
| Fast send loop | Admission rate | Completion/backlog unknown |
| Bounded round trip | Completed local exchanges | Topology and persistence limits |
| HWM reached | One admission policy | Measure bytes and process memory separately |
| Recovery backlog | Unfinished logical work | Headroom and retention required |
Explain operation costs
Creating message frames, copying bytes and converting data for transmission all cost work. Count messages and bytes separately. Each additional subscriber can add another copy. Requests awaiting replies need their IDs kept somewhere, and a latest-value map keeps a value for each topic. Instrument these variables before attributing elapsed time to one API call.
Expected hash-map lookup bounds assume a chosen implementation and inputs. Sorting evidence, process startup and rendering can dominate a tiny lab. Do not label a computed queue model or a VM clock as measured production throughput.
Budget overload and recovery
If offered work exceeds sustainable completion capacity, a finite queue buys time. Choose bounded admission, pause/rejection, controlled shedding or a durable recovery source with ownership. A recovery plan needs capacity above new arrivals to drain accumulated work.
Benchmark with representative distributions, slow consumers, skewed routes, large messages and failure/retry bursts. Report variance and unfinished work, verify correctness, and keep deployment resource/transport settings with the measurements.
Check your understanding
A service accepts 200 jobs each second and completes 150. A queue that can hold 1,000 waiting jobs starts empty. At those constant rates, how long does the queue take to fill?
Show hints
Hint 1
How many more jobs enter than leave each second?
Hint 2
Divide the available places by the number of extra jobs per second.
Show explanation
The queue grows by 50 jobs per second and fills in about 20 seconds in this model. Measure actual bursts, job sizes and retry rates before choosing a limit for a real service.
ReferencesPrimary sources for this chapter’s design case
Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.
ZeroMQ socket options
PyZMQ API