|
20 | 20 |
|
21 | 21 | BATCH_SIZE = 10 |
22 | 22 |
|
23 | | -# Large SDKs take significantly longer to run tests. Assigning higher weights |
24 | | -# ensures these packages occupy more runner slots and load-balance effectively. |
25 | | -PACKAGE_WEIGHTS = { |
26 | | - "google-cloud-compute": 5, |
27 | | - "google-cloud-compute-v1beta": 5, |
28 | | - "google-cloud-dialogflow": 5, |
29 | | - "google-cloud-dialogflow-cx": 5, |
30 | | - "google-cloud-retail": 5, |
31 | | -} |
| 23 | +# Packages that take significantly longer to run tests. |
| 24 | +# These will always be assigned to their own dedicated runner. |
| 25 | +ISOLATED_PACKAGES = [ |
| 26 | + "google-cloud-compute", |
| 27 | + "google-cloud-compute-v1beta", |
| 28 | + "google-cloud-dialogflow", |
| 29 | + "google-cloud-dialogflow-cx", |
| 30 | + "google-cloud-retail", |
| 31 | +] |
32 | 32 |
|
33 | 33 | def get_batches(): |
34 | | - """Distributes packages into batches using a greedy load-balancing algorithm.""" |
| 34 | + """Splits packages into dedicated isolated batches and evenly chunked standard batches.""" |
35 | 35 | raw_paths = sorted(glob.glob("packages/*")) |
36 | 36 | package_paths = [p for p in raw_paths if os.path.isdir(p)] |
37 | 37 |
|
38 | | - packages_with_weights = [] |
39 | | - total_weight = 0 |
| 38 | + batches = [] |
| 39 | + standard_packages = [] |
| 40 | + |
40 | 41 | for path in package_paths: |
41 | 42 | pkg_name = os.path.basename(path) |
42 | | - weight = PACKAGE_WEIGHTS.get(pkg_name, 1) |
43 | | - packages_with_weights.append((path, weight)) |
44 | | - total_weight += weight |
45 | | - |
46 | | - num_batches = math.ceil(total_weight / BATCH_SIZE) |
47 | | - if num_batches == 0: |
48 | | - num_batches = 1 |
49 | 43 |
|
50 | | - # Sort packages by weight descending (Longest Processing Time first) |
51 | | - packages_with_weights.sort(key=lambda x: x[1], reverse=True) |
52 | | - |
53 | | - batches = [[] for _ in range(num_batches)] |
54 | | - batch_weights = [0] * num_batches |
| 44 | + if pkg_name in ISOLATED_PACKAGES: |
| 45 | + # Put heavy packages into their own standalone batches immediately |
| 46 | + batches.append([path]) |
| 47 | + else: |
| 48 | + standard_packages.append(path) |
| 49 | + |
| 50 | + # Chunk the remaining standard packages by BATCH_SIZE |
| 51 | + num_standard_packages = len(standard_packages) |
| 52 | + num_standard_batches = math.ceil(num_standard_packages / BATCH_SIZE) |
55 | 53 |
|
56 | | - for path, weight in packages_with_weights: |
57 | | - # Greedily assign the package to the currently least-loaded batch |
58 | | - min_idx = batch_weights.index(min(batch_weights)) |
59 | | - batches[min_idx].append(path) |
60 | | - batch_weights[min_idx] += weight |
| 54 | + if num_standard_batches == 0 and not batches: |
| 55 | + num_standard_batches = 1 |
61 | 56 |
|
| 57 | + for i in range(num_standard_batches): |
| 58 | + start_idx = i * BATCH_SIZE |
| 59 | + chunk = standard_packages[start_idx : start_idx + BATCH_SIZE] |
| 60 | + if chunk: |
| 61 | + batches.append(chunk) |
| 62 | + |
62 | 63 | return batches |
63 | 64 |
|
64 | 65 | def get_batch_indices(): |
|
0 commit comments