datafusion-ballista icon indicating copy to clipboard operation
datafusion-ballista copied to clipboard

Deterministically stagger shuffle read fetch order instead of randomizing it

Open NoahKusaba opened this issue 3 months ago • 0 comments

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

ShuffleReaderExec::execute orders its fetch list in two steps with separate goals:

// Sort partitions for evenly send fetching partition requests to avoid hot executors within one task ... .sorted_by(|(p1_idx, _), (p2_idx, _)| Ord::cmp(p1_idx, p2_idx)) ... // Shuffle partitions for evenly send fetching partition requests to avoid hot executors within multiple tasks partition_locations.shuffle(&mut rng());

The sort builds a round-robin so one task spreads its in-flight window across producers. The shuffle then discards it: Fisher-Yates yields a uniform permutation regardless of input order, so nothing of the sort survives. The intra-task goal is not met today.

This was raised in review on #256:

▎ thinkharderdev: Why do we sort by index before shuffling here? ▎ ▎ yahoNanJing: Sorting first may be helpful for reducing the bias of random chosen. Maybe it's not necessary.

Sorting cannot reduce bias, since a uniform shuffle erases input order whatever it was; however, it produced exactly the spread its own comment describes, which the shuffle is discarding.

The cross-task goal also falls short. Each task draws its own random order, so peers can still open on the same producer.

Nothing better is available today. restrict_plan_to_partitions re-indexes each task's slice from zero, so every reader is partition 0 locally and carries nothing that says which peer it is.

Describe the solution you'd like

Stamp each local output partition with its global index among the stage's peers, carry it to the executor, and use it to rotate a deterministic round-robin over producers.

Round-robin gives the intra-task spread the sort was meant to provide. The rotation staggers peers exactly rather than probabilistically.

Describe alternatives you've considered

  • Drop the sort, keep the RNG. Matches what the code effectively does today and answers the #256 question, but leaves peers colliding.
  • Seed the RNG deterministically. Nothing stable to seed with. After restriction every reader is partition 0, so peers seed identically.
  • Assign order in the scheduler at dispatch. Needs runtime state for a result a peer index gives locally.

NoahKusaba avatar Aug 31 '26 23:08 NoahKusaba