Skip to content

flow: a Partition's pieces stay on their worker (PR 3 of the plan) - #178

Merged
winding-lines merged 4 commits into
mainfrom
flow-partition-keep
Nov 29, 2026
Merged

winding-lines merged 4 commits into
mainfrom
flow-partition-keep

Conversation

@winding-lines

Copy link
Copy Markdown
Contributor

PR 3 of the plan "Keyed partitions in flows" (DESIGN.md): a Partition's pieces stay on the worker that made them whatever their size, so a shuffle of many small pieces sits in the workers' stores (which spill), not in the head's memory.

What was built

  • remote_many(..., keep_on_worker=False): a keyword-only argument on all three forms of Client.remote_many and Runtime.remote_many. Every existing call is unchanged; Partition.submit_many passes True.
  • On the wire: the top bit of the TaskMany's result count (KEEP_ON_WORKER = 1 << 63, dista/frame.mojo, with many_word/parse_many), in task-many, task-after (MANY) and task-inputs (MANY). That count is the one field every frame that runs a TaskMany carries; task-many has no flags byte, and a trailing field would follow an argument with no length. The count is at most 2^20, so the bit was always 0: frames without the flag are byte-identical to before.
  • Head: keeps the flag on a waiting task (_Task.keep) and writes it into the count of the task-many / task-inputs frame it sends the worker, so a retry on another worker keeps it; a task-many frame goes on as it came. The driver's kept submission payload (Client._subs) has it, so a re-send after a head restart does too.
  • Worker: reads it from the count and stores every result of the task (Worker._finish), node store then spill dir, like a large one. An empty result still goes inline (the store can't map an empty file); a Seq never encodes empty.

Gate and evidence

  • 2,000 pieces of 10 KB, the head's memory doesn't grow with them (tests/test_partition_keep.mojo, test_kept_pieces_stay_off_the_head): deterministic check on the head's stats once all pieces exist: without the flag results=2000, located=0, with it results=0, located=2000. Head RSS growth from its start, printed (not asserted):

    pieces macOS without macOS with sai without sai with
    496 6.5 MB 0.9 MB 8.6 MB 0.6 MB
    2,000 24.1 MB 1.9 MB 20.9 MB 0.8 MB

    Also a flow: 125 inputs × 16 pieces, one reducer at a time; at the first partition's result the head holds results=1, located=1875; result exact.

  • Store room for a quarter of the pieces (test_pieces_past_the_store_spill_and_are_removed, DISTA_STORE_BYTES = pieces' bytes / 4 / 4 workers, large batches so partition tasks run from task-inputs): ~470 in the store and ~1,480 spilled at the first result, exact, store and spill dir empty after.

  • No flag, same bytes (test_a_program_without_the_flag_sends_the_bytes_it_sent_before): each remote_many form's frame read off a socket pair compared byte for byte with the pre-flag layout written out by hand; with the flag only the top bit differs, and the re-send copy matches. Head relay tests (test_the_head_passes_the_flag_on_and_keeps_it_for_a_retry, test_task_inputs_carry_the_flag) drive a Head in-process: the flag reaches the worker in task-many and task-inputs, and survives a retry on another worker; without it the count is as before.

Verified

  • Mac: test_partition_keep 7 runs, all pass; test_flow_partition, test_flow, test_shuffle, test_spill; the changed partition-death test 5 more times alone; tests/flow_loss.sh ×2, tests/head_restart.sh ×2, tests/compile_fail.sh, format-check, and the full pixi run test once (exit 0).
  • sai (Linux, from this branch): test_partition_keep ×6, test_flow_partition, test_flow, test_spill, the partition-death test ×5, flow_loss.sh ×2, head_restart.sh ×2. All pass. Clone removed afterwards.

Deviations (also in DESIGN.md, "PR 3, as built")

  • A lost worker now loses its small pieces too, so a loss before the barrier may read again more inputs than the one whose task died. test_a_partition_task_whose_worker_dies_reads_its_input_again expected exactly 1 rerun; it now flaked at 2 and expects ≥ 1 with submitted == INPUTS + reruns.
  • After a head restart a kept piece is claimed back, not re-sent with bytes, so it can be in FlowStats.unsized_pieces until its worker reports (head_restart.sh's partition flow shows 4).
  • _run_many's three-copies peak untouched.

For PR 4/5

A kept piece costs a file write each, and a reducer on another host now fetches each piece from its worker rather than getting small ones inline from the head (416 small fetches per reducer on AWS). Worth measuring in PR 5.

🤖 Generated with Claude Code

https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV

winding-lines and others added 4 commits November 29, 2026 06:57
A TaskMany submitted with remote_many(..., keep_on_worker=True) stores
every result on its worker whatever its size, so it spills instead of
sitting in the head's memory; a flow's Partition sets it. The flag is
the top bit of the result count in the task-many, task-after and
task-inputs frames, so frames without it are byte-identical to before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV
@winding-lines
winding-lines merged commit eedc83a into main Nov 29, 2026
12 checks passed
@winding-lines
winding-lines deleted the flow-partition-keep branch November 29, 2026 15:33
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