Skip to content

Commit

Permalink
Speed up AWS VPC validation (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4victor authored May 6, 2024
1 parent a9bfad1 commit 6405691
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/dstack/_internal/server/services/backends/configurators/aws.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import concurrent.futures
import json
from typing import List

Expand Down Expand Up @@ -138,13 +139,20 @@ def _check_vpc_config(self, session: Session, config: AWSConfigInfoWithCredsPart
regions = config.regions
if regions is None:
regions = DEFAULT_REGIONS
for region in regions:
ec2_client = session.client("ec2", region_name=region)
try:
compute.get_vpc_id_subnet_id_or_error(
# The number of workers should be >= the number of regions
with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
futures = []
for region in regions:
ec2_client = session.client("ec2", region_name=region)
future = executor.submit(
compute.get_vpc_id_subnet_id_or_error,
ec2_client=ec2_client,
config=AWSConfig.parse_obj(config),
region=region,
)
except ComputeError as e:
raise ServerClientError(e.args[0])
futures.append(future)
for future in concurrent.futures.as_completed(futures):
try:
future.result()
except ComputeError as e:
raise ServerClientError(e.args[0])

0 comments on commit 6405691

Please sign in to comment.