Skip to content

bench/shuffle: the group-by as a flow (PR 4 of the keyed-partitions plan) - #179

Merged
winding-lines merged 1 commit into
mainfrom
shuffle-flow
Nov 29, 2026
Merged

winding-lines merged 1 commit into
mainfrom
shuffle-flow

Conversation

@winding-lines

Copy link
Copy Markdown
Contributor

PR 4 of the plan "Keyed partitions in flows (plan, 2026-11-29)" in DESIGN.md.

What was built

  • deploy/shuffle_flow.mojo: the shuffle benchmark's group-by as Flow[Read[ScanGroups], Partition[SplitZones, PARTS], Reduce[MergeZones]], one input per data file. The stream reads a file a batch at a time into running totals per key and puts one item per batch: that batch's keys with the file's totals so far. The partition task keeps each key's last totals, which are the file's, and splits them by key % PARTS. The reducer is the hand-written one. Running totals keep the sums in the hand-written map task's order, so the flow's ANSWER and TOP lines are the hand-written version's to the last bit.
  • deploy/zone_hours.mojo: the code both programs share, moved out of deploy/shuffle.mojo: features, key, groups, top 10, map and reduce tasks, one-process run, check and printing. Its private names are now public, it gains Dense.add_counted, and distributed is generic over the runtime. deploy/shuffle.mojo is now its main alone, and prints what it printed before.
  • PARTS at build time: set with -D SHUFFLE_PARTS=<n> (default 16). pixi run -e data build-shuffle (bench/shuffle/build.sh) builds build/shuffle, build/shuffle-flow-16 and build/shuffle-flow-64. SHUFFLE_REDUCERS, if set, must match the binary's PARTS.
  • Modes and output: the same TAXI_MODEs as the hand-written version. both checks the flow against one process and, in the same process, against the hand-written shuffle with PARTS reducers, and prints a DIFF line for each. The program prints the same TIME zone_hours <pass> <ms> lines, and STATS zone_hours … (the flow's stats()) after the last pass.
  • CI: the data job builds the three programs.
  • Docs: bench/shuffle/README.md gains an "As a flow" section and run lines, DESIGN.md gets "PR 4, as built" and PR 4 marked done, and CHANGELOG.md one line.

Nothing in src/dista/ changed.

Verified (macOS, the shared Mac mini, local table of 24 files)

  • Gate, TAXI_MODE=both with build/shuffle-flow-16 and build/shuffle-flow-64: PASS. Against the hand-written shuffle the largest relative difference is 0 (bit-identical). Against one process it is 9.4e-14 at 16 and 9.9e-14 at 64; counts and top-10 keys are exact and the sums are within the bench's 1e-9. The hand-written version isn't bit-identical to one process either, because the process's threads add files in another order. The ANSWER/TOP lines of the flow equal build/shuffle's with SHUFFLE_REDUCERS 16 and 64.
  • The hand-written version passes TAXI_MODE=both at 16 and 64. Its ANSWER/TOP lines equal those of a build of origin/main's deploy/shuffle.mojo.
  • TAXI_MODE=local works, and a mismatched SHUFFLE_REDUCERS gives the build hint.
  • pixi run test-shuffle, test-flow-partition and test-flow pass, as do pixi run -e fmt format-check and customs v0.5.1.

Deviations (details in "PR 4, as built")

  • The stream puts running totals, not per-batch sums, so the answer is exact to the bit. An item has the same keys either way.
  • The partition task uses a flag per key, read last first, rather than a dense array.
  • Read[ScanGroups, 64], so the workers' slots set the stream count and not the default 4.
  • both also runs the hand-written version, to check against it.

First look at time (single runs of 5 passes, shared Mac, 4 workers; not PR 5's numbers)

slots/worker PARTS flow by hand
1 16 1.22–1.25 s 0.87–0.89 s
1 64 1.25–1.30 s 0.94–0.96 s
2 16 0.82–0.83 s 0.64–0.75 s
2 64 0.85–0.88 s 0.70–0.79 s

The flow is 33 to 40% slower at one slot per worker. Most of that is the read's cap, which keeps one slot free for the tasks after it: the flow reads 3 files at a time on 4 one-slot workers, where the hand-written version runs 4 map tasks. Its streams used about the same slot time, 3.40 s against the hand-written map tasks' 3.47 s. The partition tasks add 0.44 s on the free slot, 18 ms a file.

🤖 Generated with Claude Code

https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV

…lan)

deploy/shuffle_flow.mojo runs the shuffle benchmark's query as
Flow[Read[ScanGroups], Partition[SplitZones, PARTS], Reduce[MergeZones]],
one input per data file. Its stream puts each batch's keys with the file's
running totals, so the partition task keeps each key's last totals and the
answer is the hand-written version's to the last bit, at 16 and 64
partitions. PARTS is set when building (-D SHUFFLE_PARTS); the data
environment's build-shuffle task builds build/shuffle and
build/shuffle-flow-16 and -64, and the data job in CI runs it.

The row code both programs share moves to deploy/zone_hours.mojo;
deploy/shuffle.mojo prints what it printed before. TAXI_MODE=both in the
flow program checks it against one process and the hand-written shuffle,
and it prints the flow's stats after its last pass.

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