Mac mini inference serving: overlapping I/O with inference, not batching, raised throughput
How Diffio raised Mac mini throughput on I/O-bound speech restores by overlapping downloads, encoding and uploads with inference around one shared model, rather than batching.

Diffio restores speech on a fleet of Mac minis (M4 Pro, 24 GB of unified memory). Each worker now runs several jobs at once around a single copy of the model, and a burst of six uploads drains 3.3x faster.
How a worker takes a job and publishes its audio
Each mini runs one worker, which can serve our production environment, our dev environment or both. The worker used to run one job at a time, so under load users waited for whole jobs ahead of them.
The worker takes jobs from each enabled environment's edge scheduler (a Cloudflare Durable Object that queues jobs and hands them to connected workers), downloads the upload and its transcript, restores it, and publishes the result as HLS (HTTP Live Streaming) audio that plays while later parts are still restoring, then as final files.
The burst as a table, with the worst time to first audio
| Six 45 s jobs submitted at once, one mini, stems uploaded one at a time | Makespan | Median time to first audio | Worst time to first audio |
|---|---|---|---|
| One job at a time | 140 s | 63 s | 120 s |
| Three jobs at once, one model | 59 s | 16 s | 41 s |
| Six jobs at once, one model | 42 s | 6.1 s | 9.8 s |
The makespan runs from submitting the burst to the last job's completion; time to first audio runs from submitting a job until its first HLS segment is playable.
Six 45 s jobs submitted at once, one Mac mini
Overlapping I/O with one shared model, measured in this post (lower is better)
Makespan
Median time to first audio
Inference occupied 7–26% of a dev restore job's wall-clock time
The rest was downloading, decoding, MP3 and HLS encoding, and uploading through the edge.
| Clip, sampler (12 dev jobs) | Wall-clock job time | Inference time | Inference fraction |
|---|---|---|---|
| 11–45 s, flash | 7.5–23 s | 0.8–1.7 s | 7–11% |
| 11–30 s, pro | 9.9–21 s | 2.6–4.4 s | 21–26% |
| 3 min, pro | 102 s | 18 s | 18% |
What overlapping jobs can buy, at most
- 15%inference's share of dev job time
- 9–14xoverlap bound, flash (Amdahl's law)
- 4–5xthe same bound for pro
- ~1.4xthe cap for a production pro job once stems moved
Why pro spends longer in the model, and the overlap bound (Amdahl's law) and what it assumes
Across logged dev restore jobs, inference took 15% of wall-clock time. The fraction depends on the sampler: pro, which uses best-of-three sampling and selects the speech and the background separately, spends longer in the model than flash, the default.
With inference as the serial part, overlapping jobs can raise throughput by at most the inverse of the inference fraction (Amdahl's law), 9–14x for flash and 4–5x for pro, and by at most the number of jobs allowed at once; both bounds assume the I/O and encoding of different jobs overlap without contending. Once stems moved after job completion (described later), inference became about 70% of a production pro job, which caps the overlap gain for those jobs near 1.4x; the burst speedup applies to I/O-bound jobs.
A single inference thread serves several concurrent job slots
Up to six job threads do the I/O; restores queue for the one thread that runs the model.
How a restore moves through one worker
- Edge schedulerassigns jobs up to the slots the worker reports
- Job threadone of up to six; downloads and decodes the upload
- Inference queueproduction before dev, then shortest job first
- Inference threadthe one thread that loads and runs the model
- Job threadencodes and uploads HLS audio, then final files
Why one inference thread, how the queue orders restores, and how the scheduler protocol changed
Each job does its downloads, decoding, encoding and uploads on its own thread; restore jobs queue for a single inference thread, the one thread that loads and runs the model, so MLX and PyTorch MPS state stays on one thread as it did when one job thread did everything.
The inference queue serves production restores before dev ones, and within each environment shortest job first by expected inference time: audio seconds divided by the sampler's measured speed, 11x real time for pro and 35x for flash. Shortest job first can starve a long file, so the queue applies aging: a restore that has waited a bounded time or been passed over a bounded number of times goes next within its environment. A job waiting for inference stays in the "preparing audio" phase it was already reporting, and a cancel while it waits removes it before it starts.
How the scheduler protocol changed for job slots
The scheduler had assumed one job per worker, and its protocol changed with the worker. A worker tells each environment's scheduler how many more jobs it can take and which jobs it still runs there (a ready message with slots and jobIds). The scheduler assigns up to that many, re-queues any accepted job the worker no longer lists, and treats a rejection as zero open slots until the next ready. A freed slot is offered to production at once and to dev half a second later; if both environments assign the last slot at the same moment, the worker rejects one and the scheduler re-queues it without counting it against the job's retry limit.
Overlapping jobs makes each one slower, because their uploads share the mini's uplink:
Six 3 min jobs at once, six slots, flash
- 194 smakespan
- 17 smedian time to first audio (worst 31 s)
- 5.3 → 7.4 GBworker memory idle → peak, about 350 MB per running job, no swap
Inference runs one whole restore at a time, so a long file blocks the queue:
What set the burst's makespan, head-of-line blocking, and scheduling at window granularity
The burst's makespan is set by the slowest job's I/O, not by inference: inference-thread utilization was 22% over the burst, and a restore took as long with other jobs running as without.
Inference is scheduled non-preemptively, one whole restore at a time, so a long file causes head-of-line blocking: a 20-minute file holds the inference thread for about 33 s with flash and 107 s with pro.
Restores already advance window by window, so scheduling at window granularity is the next step; it needs a separate codec decoder KV cache per job, since the decoder keeps its keys and values across windows. Six 20-minute files at once are unmeasured.
Stem uploads were bound by per-request cost, not bandwidth or CPU, and now follow the job's completion
Uploaded one at a time, a 3 min file's stems took most of the job, while the worker and ffmpeg used 15 s of CPU.
One 3 min file's stems, when we measured
- ~100WAV and FLAC objects, 250 MB, each a PUT through the edge
- 0.3–0.5 sfixed overhead per PUT, in the edge
- 5–10MB/s transfer per stream
- 3–22 msnetwork round trip
What the stems are, and where the fixed per-PUT overhead comes from
A restore publishes its separated speech and background as stems; when we measured, that was about 100 WAV and FLAC objects (250 MB) for a 3 min file, each a PUT through the edge.
Each PUT costs 0.3–0.5 s of fixed overhead plus its transfer at 5–10 MB/s per stream. The overhead is in the edge, not the 3–22 ms network round trip: the edge checks the job's scheduler lease and writes to R2, Cloudflare's object store where the media lives, on every PUT. Every worker upload pays it, so caching the lease check per job is the next speedup for all of them.
The worker now uploads eight objects at a time while later chunks still encode:
Upload data and method: the queue, medians as a table, and the worker-wide AIMD limit
Uploading while later chunks are still encoding overlaps both the overhead and the per-stream transfer. At most 32 objects wait in the queue, so disk use stays bounded, and the manifest goes last, once every object it lists exists.
| 3 min file, flash, one mini | Stem upload phase, median | Job, median |
|---|---|---|
| One at a time | 88 s | 95 s |
| 8 at a time | 32 s | 39 s |
| 16 at a time | 37 s | 43 s |
How a worker-wide AIMD limit bounds uploads across six jobs
Eight at a time per job multiplied across six jobs, all contending for one home uplink. Each job still sends at most eight, and a worker-wide AIMD (additive increase, multiplicative decrease) concurrency limit, as in TCP congestion control, now bounds them together: it adds about one request per window without failures and halves on a timeout or failure, within 2–16, and like TCP it treats every failure as congestion; its effect on throughput is unmeasured. Playback outputs have priority over stems for a free request.
Since October 8 stems upload after job completion:
What the worker reports, what still uploads after, and all stage medians as a table
The worker reports job.complete once the restored audio and its playback outputs are published, then uploads the stems (FLAC chunks plus speech and background masters, the original now rendered from the upload) within a 45-minute window and reports them in a separate job.stems message. A stem failure never fails the restore. The table covers one internal API client's 60 s files on the wired mini.
| 60 s file, pro, production, wired mini, 1,627 jobs | Median |
|---|---|
| Download and decode | 0.45 s |
| Inference | 5.2 s |
| Encode | 1.3 s |
| Upload | 0.49 s |
Job (job.complete) |
7.5 s |
Stems published after job.complete |
1.5–2.5 s |
The scheduler routes each restore to the mini where its inference would start first, which ignores the uplink
Open slots alone do not say where a restore will start soonest, because a mini with free slots can still have minutes of pro queued for its one model.
How the scheduler picks a mini
- Workers reportopen slots and inference backlog, in
readyand everyping - Scheduler estimateswhen each mini's inference would start
- Ties within 10 sworker priority, then idle time
- Not seenthe uplink; the slower one got every other job
| 60 s file, pro, production | Faster uplink | Slower uplink |
|---|---|---|
| Upstream, round trip | ~50 MB/s, 3 ms | 6.7 MB/s, 22 ms (Wi-Fi) |
| Job, median (p90) | 7.5 s (8.3 s) | 8.3 s (12.7 s) |
Stems after job.complete, median by hour |
1.5–2.5 s | 5.5–8.2 s |
What workers report, how ties are broken, and the two uplinks measured
Workers also report their inference backlog (the running restore's remaining seconds and the queued restores' expected seconds) in ready and in every ping, and the scheduler sends each restore to the mini where its inference would start first.
How ties between minis are broken
Starts within 10 s of the soonest count as equal, and worker priority, set per worker by our deploy script, then idle time decide among them. Ties are judged against the soonest start, because equality within a tolerance is not transitive: judged against the running best, estimates of 0, 9 and 18 s all tie in turn and the last wins.
That backlog is the only cost routing sees, and on short files it is the same everywhere.
The two uplinks, measured
Our two minis reach Cloudflare over different home connections, one at about 50 MB/s upstream with a 3 ms round trip, the other at 6.7 MB/s and 22 ms over Wi-Fi. Once we gave them equal priority on October 14, idle models tied and the longest-idle rule sent every other job of a sequential client to the slower one.
Inference took 5.2 s on both. The faster mini's figures cover two days, the slower mini's 70 jobs since the priority change. Moving the slower mini from Wi-Fi to Ethernet did not raise its uplink, 4.5 MB/s wired, because its connection is the limit.
In-order callbacks blocked completion behind stale progress, and unretried worker messages re-ran jobs
Scheduler to backend: in order, retried
- 11 progress eventseven a short restore sent them, each retried in order
- Completion waits
job.completedsat 0.3–0.7 s behind the undelivered ones - Fixcompletion drops a job's undelivered progress events
Worker to scheduler: no retry
- Message losta completion written as the socket dropped
- Job re-runre-queued; one 95 s job finished after 196 s
- Fixworkers replay terminal messages; the scheduler deduplicates
The full account: the backend outbox and the worker link
The scheduler forwards job events to our backend (as job.queued, job.progress, job.completed and so on, the last sent when a worker reports job.complete) through an outbox, a queue in the scheduler's storage that retries each event until it is acknowledged and delivers one job's events in order. Progress within a phase is coalesced, but phase changes and the start and end of each transfer go at once, so even a short restore sent 11 progress events, and its job.completed suffered 0.3–0.7 s of head-of-line blocking behind the undelivered ones. Completion now drops a job's undelivered progress events: its event carries every output they did, and only that job's last intermediate phase and its first-audio time can be lost.
The worker's link to the scheduler had the opposite problem, no retry at all. A message written just before the scheduler dropped a socket was lost, and a worker that reconnected without reporting its completion had the job re-queued and run again: one 95 s job finished after 196 s. Workers now replay their recent terminal job messages after each reconnect, and the scheduler deduplicates them: at-least-once delivery with idempotent handling.
Outside the fleet, transcription and backend calls take longer than the restore
A 4.5 restore is conditioned on the transcript, so for an API client the fleet job sits between a transcription and the calls that record the result.
The calls around a fleet job, and the traced job as a table
The client creates a project, uploads the file, then requests a generation (one restore of that project); our backend, Cloud Functions on Google Cloud, runs the transcription, queues the fleet job and marks the generation complete.
| Stage, one 60 s pro API job | Time |
|---|---|
| Upload, create project | 1.8 s |
| Create generation | 2.0 s |
| Generation created to fleet job queued (transcription) | 4.0 s |
| Fleet job | 7.3 s |
| Fleet job done to client sees complete (2 s polling) | 3.2 s |
Across a day of our internal client's 60 s pro files, transcriptions took 5.0 s at the median and 11.8 s at the p90, so for short files the serial stages around the fleet cost more than the fleet job.
botocore's default 60 s read timeout turned unanswered R2 requests into 62 s stalls
Our backend reaches R2 through boto3: upload checks and probes, the object checks that complete a generation, and transcription artifacts.
| Over 12 hours before the fix | Took 15 s or more, most about 62 s |
|---|---|
| Upload completions | 22 of 978 |
| Generation completion checks | 26 of about 950, in pairs |
Which requests stalled and why, why they came in pairs, and what explains them
The client configured retries but no timeouts, so botocore's 60 s default read timeout applied. A request that got no answer waited the full read timeout, then its retry on another connection succeeded, so it ended normally after about 62 s. Cutting the read timeout to 10 s cut the stalls to 11–13 s, which confirms the timeout set their length.
The pairs came from our own design. The SDKs report an upload with complete_project_upload as soon as it lands, and the edge sent its own completion callback at the same moment, so two requests for the same upload, like two completion checks for the same generation, called R2 together and stalled together. The edge's callback now waits 30 s as a backup, by which time the upload is normally recorded and the callback returns at once. Stalls also hit our dev and production backends in the same seconds, although the two share no database, only R2 and the network path to it, which points outside both. A dead pooled connection is the leading explanation; stalls were more frequent after an instance had idled 1–5 minutes (4 of 18 checks, against 11 of 258), though the counts are small. Firestore lock contention is ruled out by the code: the transaction that records an upload makes no R2 call, and the R2 check runs before it.
On October 14, all 20 failed generations of our internal client were transcription timeouts from these stalls.
The backend's R2 timeouts now
- 10 sread timeout, down from botocore's 60 s default
- 5 s
connect_timeout - 5 sffprobe's
rw_timeoutwhen it reads an R2 URL
How a stall became a failure, longer timeouts for copies, TCP keepalive and logging
The stalls became failures where a step had a fixed deadline. The transcription steps that write artifacts get about 60 s, so a stalled write failed the transcription, and because the restore needs the transcript, the generation failed with it.
The client now also sets a 5 s connect_timeout, keeps a longer read timeout only for server-side copies and multipart completion, whose work grows with object size, and ffprobe reading an R2 URL uses a 5 s rw_timeout. We also turned on TCP keepalive, which does nothing here: the kernel's default idle time before the first probe is 2 hours. In the hours since, no transcription has failed. Every retried or slow R2 call is now logged with its error, which separates connect failures from reads that got no answer.
ScoreQ quality scoring runs on a low-priority CPU thread and adds no job time
ScoreQ, a no-reference speech quality model that predicts a mean opinion score (MOS), scores the middle 30 s of each restore's original and restored audio.
- Middle 30 sof each restore's original and restored audio, scored
- ~2.3 sper job, on one low-priority CPU thread
- No differencein job time, with scoring on and off
How ScoreQ is scheduled, and how quality scores reach the scheduler
It runs in onnxruntime on the CPU, from one low-priority thread per worker, off the inference thread and away from the GPU and the Neural Engine. It takes about 2.3 s per job, and runs with scoring on and off showed no difference in job time.
job.complete is unchanged; a separate job.quality message follows, sent only to a scheduler whose welcome message lists job.quality among its capabilities, because an older scheduler rejects unknown message types.
A single guidance branch is already compute-bound, so batching across users adds at most 13% throughput
Every 4.5 sampler step evaluates three classifier-free guidance branches; the GPU (through MLX) runs the branches that read the transcript, and the Neural Engine runs the rest, the split the 4.0 port introduced, without its CPU share.
- ~272GFLOP per branch forward pass
- 4.6TFLOPS, one branch's forward pass on the GPU
- 13%the most batching can add
- Under 3GB of peak memory at batch size 16
A linear fit to the sweep (5.4 ms per pass plus 52.4 ms per branch) bounds the gain from batching at 13%.
The model's size, the batch sweep as a table, why weight reuse does not help, and why batching across users is blocked
| 4.5 diffusion transformer | Value |
|---|---|
| Blocks, width, SwiGLU MLP width | 16, 1152, 3072 |
| Sequence length per guidance branch (mode token, 50 context latents from the previous window, 375 latent frames) | 426 tokens |
| Compute per branch forward pass | about 272 GFLOP |
| M4 Pro memory bandwidth | 273 GB/s |
| Batch size (guidance branches per GPU forward pass, all reading the transcript) | 1 | 2 | 3 | 4 | 8 | 16 |
|---|---|---|---|---|---|---|
| Time per branch | 59.5 ms | 56.3 ms | 53.9 ms | 53.8 ms | 53.1 ms | 52.9 ms |
Reading the weights once per pass takes about 2 ms, so weight reuse, the usual reason to batch, is not what batching would buy here. Peak memory stays under 3 GB at batch size 16; batching across users is blocked by the implementation instead. Branches from different users have different windows and usually different noise levels, while the forward pass shares one window's condition projections, transcript keys and values and context, and one noise level's adaLN modulation, across its batch; and the Neural Engine's fixed-shape Core ML graphs run one branch at a time.
A second copy of the model time-slices the same GPU and costs 8.1 GB
The second copy gets no hardware the first was not using, so each file takes twice as long:
All concurrency runs, footprint by process, and why a second copy is not a serving design
Two copies of the model each restoring a file took twice as long per file as one copy alone, in all three cases we ran. As a serving design, two worker copies would each overlap I/O with inference the way job slots do, so they would raise throughput only as much as slots do, and a third copy does not fit in memory.
| Restores running at once | 45 s file, flash | 3 min file, flash | 45 s file, pro |
|---|---|---|---|
| 1 | 1.5–1.7 s | 5.4 s | 4.6 s |
| 2 (each) | 3.0–3.3 s | 11.5 s | 8.7–8.9 s |
| 3 (each) | 7–26 s, swapping | ||
| 4 | Metal out-of-memory error |
| Process of one warm model | Footprint |
|---|---|
| Main process: MLX transformer, PyTorch MPS for the first window's speech encoder (Metal memory 5.8 GB) | 6.4 GB |
| CPU process: the next window's first six Granite speech-encoder layers and transcript encoder | 1.2 GB |
| Neural Engine process: Core ML guidance branches and the codec | 0.5 GB |
| Total | 8.1 GB |
4.5 no longer runs part of each MLP on the CPU, which freed the CPU for the speech-encoder work. The 4.0 port reported 10–15x slowdowns with two processes, when its main process alone held 14 GB.
The default open-file limit is 256, so a job must close every file descriptor it opens
A process started by launchd or an SSH session on macOS gets a soft limit of 256 open files (launchctl limit maxfiles prints 256 unlimited).
How many descriptors a worker holds, and the counts as a table
An idle worker holds 37 descriptors, mostly shared-memory IPC segments and pipes to its helper processes, and a running job adds about 25: TCP sockets for its parallel HLS and file uploads, plus ffmpeg pipes and segment files. The default therefore leaves room for about eight jobs.
| File descriptors in the worker process | Count |
|---|---|
| Idle | 37 |
| Peak, six 45 s jobs on a fresh worker | 184 (134 sockets) |
| Peak, six 3 min jobs on a fresh worker | 147 |
| After one burst of six jobs, before the leak fixes | 187 |
| After every burst, with the fixes | 37 |
Two leaks turned that margin into failures.
The two leaks, the burst that hit the limit, and the startup fix
Each job's HTTP client kept its connection pool open after the job ended, and each of its two HLS ffmpeg encoders kept a stderr pipe open in the worker. In the burst after one that left 187 descriptors open, the worker crossed 256: a job failed with OSError: [Errno 24] Too many open files, and uploads failed with nodename nor servname provided, a name-resolution error that disappeared with the leaks. Each job now closes its connection pool, and ffmpeg's errors go to a file instead of a pipe.
Raising the soft limit at startup
The worker also raises its soft limit at startup with setrlimit(RLIMIT_NOFILE), which ffmpeg and the helper processes inherit. macOS rejects an unlimited soft limit, and setrlimit(2) recommends min(OPEN_MAX, hard limit), which is 10240 here. Doing it in code covers the service and the same code started from a shell for smoke tests and benchmarks; a NumberOfFiles entry in a LaunchDaemon's SoftResourceLimits would also set the system-wide kern.maxfiles.
Long jobs and days of uptime, not bursts, grew the worker past 24 GB
The burst peak above is from a fresh worker. In service, one 60-minute restore pushed the worker past physical memory into 8.6 GB of swap, and an idle worker held 11 GB after a day of jobs. Three things held memory that no burst of short jobs exposes:
The three things that held memory, how each is now released, and what is still unmeasured
- The inference thread kept a reference to the last restore it finished, with its full-length arrays, until the next restore replaced it. It now releases the finished job.
- ScoreQ's onnxruntime session kept a CPU memory arena at its high-water mark, 2.5 GB after a few jobs and growing. The arena is now off.
- Each job's full-length audio timelines lived in anonymous memory, which under pressure macOS can only compress or swap. They are now shared memory-mapped files in the job's folder, whose dirty pages the kernel writes back to their own file and drops; they are released when the job unmaps them and deletes the folder. The model's MLX and Metal memory and short-lived arrays stay anonymous.
A 60-minute restore has not been re-measured since the fixes, and an unidentified allocation still accumulates: after several days of production uptime, one mini held 2.3 GB of swap, and redeploying the worker brought that to 0.5 GB.
- 8.6 GBswap after one 60-minute restore
- 11 GBheld by an idle worker after a day of jobs
- 2.5 GBScoreQ's CPU memory arena after a few jobs
- 2.3 → 0.5 GBone mini's swap after days of uptime, then after a redeploy
Outputs are byte-identical; an unidentified allocation still accumulates (2.3 GB of swap after days of uptime).
Host setup for an unattended Mac mini
Keeping each mini a dedicated worker host with free disk, logging it in without a person on macOS 27, and the host and deploy settings that survive reboots, crashes and failed deploys have their own post: Running an unattended Mac mini fleet.
What the companion post covers
- Worker only: no desktop apps; warnings on stray processes and swap
- Disk: startup sweep, warning below 20 GB free, two releases kept
- Console user: auto-login stops macOS 27's audiomxd and configd loop
- kcpassword: written by hand, since sysadminctl fails on macOS 27
- System Settings: full disk access over SSH and Screen Sharing
- Deploys: LaunchDaemon, smoke restore, one mini at a time
Sources
- Diffio Mac mini serving measurements
- Diffio production telemetry, October 13–14, 2026 (not published)
- botocore Config reference
- FFmpeg protocols documentation
All 6 sources and what each supports
- Diffio Mac mini serving measurements: the dev job timings, burst runs with per-job marks, the GPU batch sweep and its fit, the model-concurrency runs, per-process memory, file-descriptor counts before and after the leak fixes, inference times per file and the host figures behind the tables. The stem upload benchmark and the ScoreQ timing come from separate runs on the same minis and are not in this file; thresholds come from our worker's code and configuration.
- Diffio production telemetry, October 13–14, 2026 (not published): per-stage fleet job timings from our edge scheduler's job events (the 60 s pro split, the wired and Wi-Fi mini comparison), separated-track timing from the workers' logs, the traced API job and transcription times from backend events, and the R2 stall counts from Cloud Run request logs, in the routing, callback, API-path and R2 sections; the uplink figures are 25 MB uploads to Cloudflare's speed test endpoint from each mini. Queue, routing, upload-limit, memory and timeout settings come from our worker, edge and backend code.
- botocore Config reference:
connect_timeoutandread_timeoutdefault to 60 seconds, andtcp_keepaliveonly sets the socket option, in the R2 section. - FFmpeg protocols documentation: the
rw_timeoutprotocol option, in the R2 section. - setrlimit(2), Apple man page: the rejection of an unlimited
RLIMIT_NOFILEsoft limit and themin(OPEN_MAX, rlim_max)recommendation, in the open-file section. - launchd.plist(5):
SoftResourceLimitssettingkern.maxfilesfor a daemon, in the open-file section.