Skip to content

Commit 4d5e55d

Browse files
committed
remove weighting
1 parent 1aab0d5 commit 4d5e55d

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

ci/get_batches.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,46 @@
2020

2121
BATCH_SIZE = 10
2222

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+
]
3232

3333
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."""
3535
raw_paths = sorted(glob.glob("packages/*"))
3636
package_paths = [p for p in raw_paths if os.path.isdir(p)]
3737

38-
packages_with_weights = []
39-
total_weight = 0
38+
batches = []
39+
standard_packages = []
40+
4041
for path in package_paths:
4142
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
4943

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)
5553

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
6156

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+
6263
return batches
6364

6465
def get_batch_indices():

0 commit comments

Comments
 (0)