Skip to content

perf(batch): overlap worker artifact I/O with GPU work - #22352

Merged
Git-on-my-level merged 1 commit into
mainfrom
lane/opus-worker-io
Oct 19, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lane/opus-worker-io

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Why

PipelineWorker.process_batch held 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):

  • Prefetch. _DecodePrefetch fetches/decrypts/decodes items ahead of the one on the GPU, and the worker consumes them strictly in admitted order. At most io_concurrency items are submitted but not yet consumed. Beyond the next item, the ones ahead must fit in PREFETCH_AHEAD_SECONDS = 1800 audio 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 (<= 7200s per group) is unchanged. There is never more than one decoded hour-scale batch.
  • Parallel encrypted persistence. persist(item, payload) runs on the same bounded pool while the GPU diarizes the next item, with at most io_concurrency writes in flight. Results keep their admitted position. A persist failure is still a per-item persist-stage failure, handled on the calling thread outside any exception handler.
  • Unchanged. VAD, ASR, padded retry, diarization, cap-dispatch authorization and live-words checks all stay on the calling thread under the existing chain lock. The tests assert that GPU fakes only ever run on the caller's thread and never overlap. On a fatal CUDA error the flight cancels queued fetches and waits for running fetches/writes before raising, so no IO outlives the flight.
  • Knob. BATCH_PIPELINE_WORKER_IO_CONCURRENCY defaults to 3; 1 restores 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 to 1, no deploy of code needed beyond the env change. It is registered in config/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_io runs 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).

items io_concurrency=1 (before) 2 3 (default) 4
7 4.990 s 2.719 s 2.266 s 2.157 s
8 5.681 s 3.248 s 2.733 s 2.544 s

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-heavy with nice -n 19:

  • new 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.
  • unchanged existing suites: worker 91, runtime 16, pump 14, validation disposition 16, empty disposition 30, terminal empty 35, quarantine 19, cohort config 11, runtime env validator 146, bench diarizer 9.

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._write with 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

View guided diff Turn on auto-fix

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T03:58:50.230506Z b45b1e8 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +315 to +318
self._io = (
ThreadPoolExecutor(max_workers=self.io_concurrency, thread_name_prefix='batch-worker-io')
if self.io_concurrency > 1
else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +248 to +251
self._consumed += 1
# Start the following fetches before blocking: they overlap this
# item's wait and its VAD on the GPU.
self._fill()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit b553997 into main Oct 19, 2026
64 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/opus-worker-io branch October 19, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant