Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix test sharding #156768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Oct 14, 2024

Also cleans up #156762

Pre-launch checklist

@andrewkolos andrewkolos changed the title remove bringup: true on Windows build_tests remove bringup: true from Windows build_tests Oct 14, 2024
@andrewkolos andrewkolos marked this pull request as ready for review October 14, 2024 23:44
Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it!

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewkolos
Copy link
Contributor Author

Changed my mind, did you check the failures here? https://ci.chromium.org/ui/p/flutter/builders/luci.flutter.staging/Windows%20build_tests_8_8

From this:

dart --enable-asserts C:\b\s\w\ir\x\w\flutter\dev\bots\test.dart
 dart --enable-asserts C:\b\s\w\ir\x\w\flutter\dev\bots\test.dart
▌16:49:15▐ STARTING ANALYSIS
▌16:49:15▐ SHARD=build_tests
▌16:49:15▐ SUBSHARD=8_8
Selecting subshard 8 of 8 (tests 29-25 of 25)
╔═╡ERROR #1╞════════════════════════════════════════════════════════════════════
║ UNEXPECTED ERROR!
║ RangeError (start): Invalid value: Not in inclusive range 0..25: 28
║ #0      RangeError.checkValidRange (dart:core/errors.dart:360:7)
║ #1      List.sublist (dart:core-patch/growable_array.dart:84:38)
║ #2      selectIndexOfTotalSubshard (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/utils.dart:577:16)
║ #3      runShardRunnerIndexOfTotalSubshard (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/utils.dart:530:37)
║ #4      _runBuildTests (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/test.dart:360:9)
║ #5      _runFromList (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/utils.dart:601:23)
║ #6      selectShard (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/utils.dart:526:62)
║ #7      main (file:///C:/b/s/w/ir/x/w/flutter/dev/bots/test.dart:127:11)
║ #8      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
║ #9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
║ 
║ The test.dart script should be corrected to catch this error and call foundError().
║ Some tests are likely to have been skipped.
╚═══════════════════════════════════════════════════════════════════════════════

@andrewkolos
Copy link
Contributor Author

Let T be the number of tests. Let S be the number of shards. It looks like for some quantities of T and S, too many tests are assigned to each shard. The formula is tests per shard = ceil(T / S).

In Windows build_tests, there are 25 tests. Before, ceil(25/7) = 4 tests were assigned to each shard. Now, (25/8) = 4 tests are assigned to each shard. No change.

So shards 1-7 are responsible for tests 1-25 (27 clamped down to 25). They still are. Shard 8 is responsible the next 4 tests starting with 29, which doesn't make sense.

I think we need a smarter distribution formula. Some shards need to be assigned 3 tests, some need to be assigned 4.

@andrewkolos
Copy link
Contributor Author

code:

List<T> selectIndexOfTotalSubshard<T>(List<T> tests, {String subshardKey = kSubshardKey}) {

@andrewkolos andrewkolos force-pushed the remove-bringup-from-windows-build-tests branch from 54a239d to 6e812a5 Compare October 16, 2024 04:47
@andrewkolos andrewkolos changed the title remove bringup: true from Windows build_tests fix test sharding Oct 16, 2024
Comment on lines 573 to 592
// While there exists a closed formula figuring out the range of tests this
// shard is resposible for, modeling this as a simulation of distributing
// items equally into buckets is more intuitive.
//
// A bucket represents how many tests a shard should be allocated.
final List<int> buckets = List<int>.filled(total, 0);
// First, allocate an even amount of items to each bucket.
for (int i = 0; i < buckets.length; i++) {
buckets[i] = (tests.length / total).floor();
}
// For the N leftover items, put one into each of the first N buckets.
final int remainingItems = tests.length % buckets.length;
for (int i = 0; i < remainingItems; i++) {
buckets[i] += 1;
}

// Lastly, compute the indices of the items in buckets[index].
final int numberOfItemsInPreviousBuckets = index == 0 ? 0 : buckets.sublist(0, index - 1).sum;
final int start = (numberOfItemsInPreviousBuckets + 1) - 1;
final int end = (start + buckets[index - 1]) - 1;
Copy link
Contributor Author

@andrewkolos andrewkolos Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formula for directly computing start and end would look something like this:

  // The idea here is that we distribute the tests perfectly equally amongst the shards.
  // That is, each shard gets (tests.length / total).floor() tests.
  // However, this leaves N = (tests.length % total) tests left over, so we will
  // put one more test into the first N shards. We call these shards "busy" shards.
  final int busyShards = tests.length % total;
  final int testsPerBusyShard = (tests.length / total).ceil();
  final int testsPerOtherShard = (tests.length / total).floor();

  final int zeroIndexed = index - 1;

  final int start = zeroIndexed <= busyShards
      ? zeroIndexed * testsPerBusyShard
      : (busyShards) * testsPerBusyShard +
          (zeroIndexed - busyShards) * testsPerOtherShard;
  final int end = start +
      (zeroIndexed <= busyShards ? testsPerBusyShard : testsPerOtherShard) -
      1;
}

@andrewkolos
Copy link
Contributor Author

andrewkolos commented Oct 16, 2024

RE the question of "how did we not run into problem this earlier," I plotted the value of start for the last shard as a function of how many shards there are and how many tests there are.

The column number corresponds to how many shards there are. The row number corresponds to how many tests there are. Essentially, as more shards are added, the more likely it becomes that the current logic for subsharding will assign the last shard a range that exceeds the number of tests that exists.

(this isn't meant to be legible)
image

@andrewkolos andrewkolos marked this pull request as draft October 16, 2024 20:35
@flutter-dashboard

This comment was marked as spam.

@andrewkolos andrewkolos force-pushed the remove-bringup-from-windows-build-tests branch from 0768027 to e2ea927 Compare October 16, 2024 21:05
@andrewkolos andrewkolos mentioned this pull request Oct 16, 2024
9 tasks
@andrewkolos andrewkolos force-pushed the remove-bringup-from-windows-build-tests branch from d7c6c73 to bfa79c4 Compare October 17, 2024 05:39
@andrewkolos andrewkolos marked this pull request as ready for review October 17, 2024 19:14
@andrewkolos
Copy link
Contributor Author

andrewkolos commented Oct 17, 2024

@christopherfujino This is ready for review again. There was an off-by-one error in the returned interval.

final int testsPerShard = (tests.length / total).ceil();
final int start = (index - 1) * testsPerShard;
final int end = math.min(index * testsPerShard, tests.length);
// While there exists a closed formula figuring out the range of tests this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we unit test this code, given it had a bug and how hard it was to fix it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend pulling this into its own function, to make testing easier--when doing that, I would recommend passing the index as index - 1, so that the function can just pretend its 0-indexed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we unit test this code, given it had a bug and how hard it was to fix it?

Done

I would recommend passing the index as index - 1, so that the function can just pretend its 0-indexed.

I would like any parameter representing the subshard index to represent it exactly. For example, if the current subshard is 1_9, then I would be (slightly) surprised if a variable named subshardIndex (or similar) was set to 0.

@christopherfujino
Copy link
Contributor

The logic here seems right to me.


// Lastly, compute the indices of the items in buckets[index].
final int numberOfItemsInPreviousBuckets = index == 0 ? 0 : buckets.sublist(0, index - 1).sum;
final int start = (numberOfItemsInPreviousBuckets + 1) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify this to final int start = numberOfItemsInPreviousBuckets;?

Which is more intuitive is maybe subjective, but to me this is just more confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewkolos andrewkolos force-pushed the remove-bringup-from-windows-build-tests branch from bfa79c4 to 40659ea Compare October 21, 2024 04:29
Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 23, 2024
@auto-submit auto-submit bot merged commit eccf4ee into flutter:master Oct 23, 2024
145 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
Also cleans up flutter#156762

<details>

<summary> Pre-launch checklist </summary> 

</details>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants