Skip to content

Non-blocking task dispatch so wide fan-outs launch in parallel (#70) - #75

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/70-nonblocking-submit
Jul 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/70-nonblocking-submit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Collaborator

What

Makes SpawnTaskHandler.submit() non-blocking. It previously blocked on launchProcess.waitFor(), which serialized every launch on Nextflow's single task-monitor thread (~3s each). On a real N=108 fan-out that meant ~5m44s just to dispatch and a peak of ~60 concurrent instances — never 108.

Now submit() starts spawn task run and returns immediately; the launch round-trips overlap.

How

  • A daemon thread drains the subprocess's merged stdout (redirectErrorStream) — required so the OS pipe buffer can't fill and wedge the subprocess — waitFor()s, and publishes volatile launchDone/launchExit/launchOutput (launchDone written last, establishing happens-before for the other two). It deletes the spec file only after the process exits (spawn has read it by then).
  • checkIfRunning() returns false while !launchDone ("still dispatching"), then throws AbortOperationException on a non-zero exit (surfacing a launch failure), else proceeds to the existing RUNNING probe.

Why it's safe (verified against Nextflow 26.04.3 bytecode)

TaskPollingMonitor.checkTaskStatus wraps checkIfRunning()/checkIfCompleted() in try/catch → handler.kill() + handleException() — the standard terminal task-failure path. Moving the launch-failure throw from submit() to checkIfRunning() therefore fails the task exactly as before. killTask() runs spawn terminate by taskId, a no-op when nothing launched, so this stays leak-safe (cost safety is existential). finally always sets launchDone, and isSubmitTimeout() is a further backstop, so a task can't wedge in SUBMITTED.

Scope

This overlaps dispatch; it does not fix the per-task instance-boot tax (Little's Law) — peak concurrency improves but is still capped until pooled workers land. This is Phase 0 of the plan in spawn docs/pooled-task-execution-design.md; the deeper fix is the pooled-worker design (spawn Phase 1).

Testing

Compiles (JDK17) and the full Spock suite is green. The suite is all static-helper tests (the handler needs a real TaskRun; @CompileStatic makes Process/TaskRun mocking heavy), so the concurrency behavior itself is validated at the Phase 2 real N=108 run, not in unit tests.

Refs #70.

@scttfrdmn
scttfrdmn merged commit 37a9e25 into main Jul 31, 2026
4 checks passed
@scttfrdmn
scttfrdmn deleted the feat/70-nonblocking-submit branch July 31, 2026 02:46
scttfrdmn added a commit that referenced this pull request Jul 31, 2026
Ships pool mode (spawn.pool, #76) + non-blocking dispatch (#75) in a release.
Also a post-audit doc refresh: 'How it works' now describes spawn task run +
durable S3 completion (not the stale spawn launch/spored complete); pool section
requires spawn >= v0.97.0; design docs marked shipped/implemented; runbook pins
>= v0.97.0 and fixes the run-id derivation; version pins bumped to 0.10.0.
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