Improve Sharding #1: Implement Bin packing (#2880)
Replaced naive round-robin sharding with Longest Processing Time first
Bin-Packing to have better balancing workload across runners.
1. Data Pipeline (GCP Scheduled Query)
- Added a daily scheduled query in BigQuery that aggregates 14-day
rolling median test durations per (target, platform) and exports them to
a static JSON file on GCS
- Object versioning (14-day retention) is enabled so the pinned version
stays readable after the daily export.
2. The Bin-Packing Algorithm (bazelci.py)
- Reads durations from the GCS export. New/unknown tests fall back to
the platform's median duration.
Sort (LPT): Sorts targets descending by duration: (-duration,
target_name).
- Iterates from heaviest to lightest test, greedily assigning each to
the shard with the lowest accumulated runtime using a min-heap.
- All runner VMs independently compute the exact same shard assignments
(tie-breaking by shard_index).
3. Notes:
- All shards use the same version of the durations file: the pipeline
step resolves its GCS generation once and passes it to every shard.
- If downloading or reading the durations file fails, the job fails (and
Buildkite retries it) instead of falling back to round-robin, so shards
never mix strategies.
- Feature-flagged with USE_SMART_SHARDING=true; So merging this won't
affect code-orange until we actually enable the flag
Next step: Keeping tests from the same package together on the same
machine so they can share cache and run even faster.
3 files changed