Repository navigation
perf(batch): overlap worker artifact I/O with GPU work - #22352
Conversation
Fetch/decrypt/decode the next items while the current one is on the GPU, and run encrypted result writes while later items diarize. Both are bounded by BATCH_PIPELINE_WORKER_IO_CONCURRENCY (default 3, 1 = serial). Prefetch stays inside the existing two-audio-hour decode group and within 1800 audio seconds ahead. Model calls, CUDA work and the chain lock stay on the calling thread; a fatal GPU error waits for outstanding IO. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b45b1e8026
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self._io = ( | ||
| ThreadPoolExecutor(max_workers=self.io_concurrency, thread_name_prefix='batch-worker-io') | ||
| if self.io_concurrency > 1 | ||
| else None |
There was a problem hiding this comment.
Use the managed storage executor for artifact I/O
Creating a private ThreadPoolExecutor here bypasses the repository's executor lifecycle and observability: batch_pipeline_runtime.main() calls shutdown_executors(), which only cancels registered pools, so these GCS fetch/upload threads are neither reported by executor-health metrics nor explicitly stopped during worker shutdown. Route this bounded work through the managed storage executor (with the existing context-propagating submission helper) or register an equivalent managed pool rather than constructing an ad-hoc executor.
AGENTS.md reference: backend/AGENTS.md:L263-L276
Useful? React with 👍 / 👎.
| self._consumed += 1 | ||
| # Start the following fetches before blocking: they overlap this | ||
| # item's wait and its VAD on the GPU. | ||
| self._fill() |
There was a problem hiding this comment.
Refill only after consuming the current decode
When the current decode is slower than later ones, _consumed is incremented and _fill() runs before future.result() returns, so the still-running current future is excluded from outstanding and the audio-seconds calculation. This permits limit + 1 submitted-but-unconsumed decodes—and potentially an extra decoded hour-scale buffer—despite the class contract and memory bound. Resolve the current future first, then increment and refill before returning the decoded samples; the new fetches will still overlap the caller's VAD work.
Useful? React with 👍 / 👎.
Why
PipelineWorker.process_batchheld the chain lock while each item's artifact fetch/decrypt/decode ran serially before VAD. Each item's encrypted result write also ran serially after diarization. The GPU sat idle during all of it (see the worker-profile investigation in #22324). Production flights average about 7 items and 287 audio seconds.Change
backend/diarizer/batch_pipeline.py, inside_process(one bounded decode group):_DecodePrefetchfetches/decrypts/decodes items ahead of the one on the GPU, and the worker consumes them strictly in admitted order. At mostio_concurrencyitems are submitted but not yet consumed. Beyond the next item, the ones ahead must fit inPREFETCH_AHEAD_SECONDS = 1800audio seconds (about 58 MB PCM16 plus 115 MB float32 in transit). Prefetch never crosses into the next two-audio-hour group, so the existing decoded-host-memory bound (<= 7200sper group) is unchanged. There is never more than one decoded hour-scale batch.persist(item, payload)runs on the same bounded pool while the GPU diarizes the next item, with at mostio_concurrencywrites in flight. Results keep their admitted position. A persist failure is still a per-itempersist-stage failure, handled on the calling thread outside any exception handler.BATCH_PIPELINE_WORKER_IO_CONCURRENCYdefaults to3;1restores the exact serial path with no threads. The maximum is 8, and malformed values fall back to 3. It is on by default. Rollback: set it to1, no deploy of code needed beyond the env change. It is registered inconfig/feature-flags.yaml, the deployment classification and the rendered registry. The chart is untouched, so the code default applies.Numbers (latency-model fakes, wall clock)
python -m tests.unit.test_batch_pipeline_worker_ioruns 7 (and 8) items × 41 s with these modeled latencies: GCS fetch+decode 150–400 ms, encrypted write 100–300 ms, VAD 50 ms/item, ASR 120 ms/batch, diarize 150 ms/item (seeded; median of 3).That's −2.72 s per 7-item flight at the default, or 55% of that modeled flight. Measured against the observed 20.25 s mean inter-completion interval, removing about 2.7 s would be roughly 13% more leases/min per node. That only holds if production fetch/write latencies are in the modeled range; this is not yet measured. The stage timers from #22324 (
fetch_decode,encrypted_persistence) are the production check. The PR #22201 sim is single-threaded virtual time and cannot express thread overlap, so it was not used for these numbers.How verified
Targeted pytest, run under
omi-heavywithnice -n 19:tests/unit/test_batch_pipeline_worker_io.py: 18 passed, 3 consecutive runs. It covers wall-time reduction with identical results and order, GPU thread ownership and no GPU overlap, count and audio-seconds prefetch bounds, no prefetch across decode groups, per-item fetch/persist failure isolation, fatal VAD/diarize errors draining IO, the serial setting using no threads, and knob parsing.No GPU, deployment or production measurement is claimed.
Product invariants affected
None. Lease, privacy-generation and artifact-registration semantics are unchanged: each write still runs
ArtifactStore._writewith its own authorize/register/recheck. Concurrent callers use the thread-safe Firestore client and the GCS client.Failure-Class: none
Scope note: pump-level flight overlap, post-flight publication/merge and VAD/diarization model batching belong to other lanes and are untouched.
🤖 Generated with Claude Code