Skip to content

Commit 5642d6c

Browse files
committed
terraform/aws: Parallelize region discovery in gen_kconfig_location
The gen_kconfig_location script was querying AWS for availability zone information for each region (20-30 regions) sequentially. Each region query required a separate AWS API call to describe_availability_zones, resulting in 5-15 seconds of serial API calls. This change parallelizes the availability zone discovery using ThreadPoolExecutor, allowing all regions to be queried concurrently. This reduces the total execution time from the sum of all requests to approximately the time of the slowest single request, providing a 10-20x speedup for first-time runs. The output order is preserved by collecting results in a dictionary and printing them in the original region order. Generated-by: Claude AI Signed-off-by: Chuck Lever <[email protected]>
1 parent de06bb0 commit 5642d6c

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

terraform/aws/scripts/gen_kconfig_location

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ it to construct the "locations" Kconfig menu.
99
import sys
1010
import argparse
1111

12+
from concurrent.futures import ThreadPoolExecutor, as_completed
1213
from botocore.exceptions import ClientError, NoCredentialsError
1314

1415
from aws_common import (
@@ -136,9 +137,36 @@ def output_locations_kconfig(regions):
136137
)
137138

138139
template = environment.get_template("zone.j2")
140+
141+
# Parallelize availability zone discovery for all regions
142+
region_infos = {}
143+
with ThreadPoolExecutor(max_workers=20) as executor:
144+
# Submit all tasks
145+
future_to_region = {
146+
executor.submit(
147+
get_region_info, regions, region["region_name"], True
148+
): region["region_name"]
149+
for region in regions
150+
}
151+
152+
# Collect results as they complete
153+
for future in as_completed(future_to_region):
154+
region_name = future_to_region[future]
155+
try:
156+
region_info = future.result()
157+
if region_info:
158+
region_infos[region_name] = region_info
159+
except Exception as exc:
160+
print(
161+
f"Error discovering availability zones for {region_name}: {exc}",
162+
file=sys.stderr,
163+
)
164+
165+
# Print results in original order
139166
for region in regions:
140-
region_info = get_region_info(regions, region["region_name"], True)
141-
if region_info:
167+
region_name = region["region_name"]
168+
if region_name in region_infos:
169+
region_info = region_infos[region_name]
142170
print()
143171
print(
144172
template.render(

0 commit comments

Comments
 (0)