Skip to content
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

Speed up AWS VPC validation #1196

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
Loading