Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This file is used to list changes made in each version of the aws-parallelcluste
**BUG FIXES**
- Fix dynamic nodes getting stuck in `COMPLETING` state indefinitely, holding their jobs, when the backing instance
of a node with jobs is terminated and its private IP is reused by another compute node.
- Fix compute nodes with more than 10 network interfaces each failing to launch in large numbers at once.

3.16.2
------
Expand Down
36 changes: 31 additions & 5 deletions src/slurm_plugin/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
BOTO3_PAGINATION_PAGE_SIZE = 1000
BOTO3_MAX_BATCH_SIZE = 50

# RunInstances rejects a request launching more network interfaces than allowed (MaxCount multiplied by the network
# interfaces of each instance) with this code, launching nothing. Instance types with many network interfaces
# (e.g. p6-b300 with 17) hit it with the default launch batch size, so the batch is split and launched again.
REQUEST_ATTACHMENT_LIMIT_ERROR_CODE = "AttachmentLimitExceeded"


def _get_launch_error_code(exception):
"""Return the EC2 error code of a failed launch, None if it is unknown."""
if isinstance(exception, ClientError):
return exception.response.get("Error", {}).get("Code")
return getattr(exception, "code", None)


class HostnameTableStoreError(Exception):
"""Raised when error occurs while writing into hostname table."""
Expand Down Expand Up @@ -948,7 +960,9 @@ def _launch_instances( # noqa: C901

fleet_manager = self._get_fleet_manager(all_or_nothing_batch, compute_resource, queue)

for batch_nodes in grouper(slurm_node_list, launch_batch_size):
pending_batches = list(grouper(slurm_node_list, launch_batch_size))
while pending_batches:
batch_nodes = pending_batches.pop(0)
try:
launched_ec2_instances = self._launch_ec2_instances(
batch_nodes, compute_resource, fleet_manager, instances_launched, job, queue
Expand All @@ -962,16 +976,28 @@ def _launch_instances( # noqa: C901
# This path handle the CreateFleet case, which doesn't fail when no capacity is returned
return instances_launched
except (ClientError, Exception) as e:
error_code = _get_launch_error_code(e)
if error_code == REQUEST_ATTACHMENT_LIMIT_ERROR_CODE and len(batch_nodes) > 50:
# Nothing was launched: retry this and the remaining batches at half the size
split_batch_size = (len(batch_nodes) + 1) // 2
logger.warning(
"Launch request for nodes %s exceeded the network interfaces allowed in a single "
"request, retrying in batches of %s nodes",
print_with_count(batch_nodes),
split_batch_size,
)
remaining_nodes = [node for batch in [batch_nodes, *pending_batches] for node in batch]
pending_batches = list(grouper(remaining_nodes, split_batch_size))
continue

logger.error(
"Encountered exception when launching instances for nodes %s: %s",
print_with_count(batch_nodes),
e,
)
update_failed_nodes_parameters = {"nodeset": set(batch_nodes)}
if isinstance(e, ClientError):
update_failed_nodes_parameters["error_code"] = e.response.get("Error", {}).get("Code")
elif isinstance(e, Exception) and hasattr(e, "code"):
update_failed_nodes_parameters["error_code"] = e.code
if error_code is not None:
update_failed_nodes_parameters["error_code"] = error_code
self._update_failed_nodes(**update_failed_nodes_parameters)

if job and all_or_nothing_batch:
Expand Down
69 changes: 69 additions & 0 deletions tests/slurm_plugin/test_instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest
import slurm_plugin
from assertpy import assert_that
from botocore.exceptions import ClientError
from slurm_plugin.common import ScalingStrategy
from slurm_plugin.fleet_manager import EC2Instance, LaunchInstancesError
from slurm_plugin.instance_manager import (
Expand Down Expand Up @@ -4096,6 +4097,74 @@ def test_launch_instances_reports_blocking_error_instead_of_retrying_throttling(

assert_that(instance_manager.failed_nodes).is_equal_to({"VcpuLimitExceeded": {"queue2-dy-fleet-ondemand-1"}})

@staticmethod
def _mock_run_instances_with_network_interfaces(mocker, network_interfaces_per_instance, max_per_request=5000):
"""Mock RunInstances rejecting requests over the network interfaces per request limit, like EC2 does."""
requested_counts = []

def _run_instances(region, boto3_config, run_instances_kwargs):
count = run_instances_kwargs["MaxCount"]
requested_counts.append(count)
if network_interfaces_per_instance > max_per_request or count * network_interfaces_per_instance > (
max_per_request
):
raise ClientError(
{"Error": {"Code": "AttachmentLimitExceeded", "Message": "exceeds the maximum allowed limit"}},
"RunInstances",
)
first_id = sum(requested_counts[:-1])
return {
"Instances": [
{
"InstanceId": f"i-{first_id + index}",
"PrivateIpAddress": f"ip.{first_id + index}",
"PrivateDnsName": f"ip-{first_id + index}",
"NetworkInterfaces": [],
"LaunchTime": datetime(2020, 1, 1, tzinfo=timezone.utc),
}
for index in range(count)
]
}

mocker.patch("slurm_plugin.fleet_manager.run_instances", side_effect=_run_instances)
return requested_counts

@pytest.mark.parametrize("scaling_strategy", [ScalingStrategy.BEST_EFFORT, ScalingStrategy.ALL_OR_NOTHING])
def test_launch_instances_splits_batch_over_interfaces_limit(self, mocker, instance_manager, scaling_strategy):
"""A batch over the network interfaces per request limit is launched again in smaller batches."""
requested_counts = self._mock_run_instances_with_network_interfaces(mocker, network_interfaces_per_instance=17)
node_list = [f"queue1-st-c5xlarge-{index}" for index in range(1, 601)]

instances_launched = instance_manager._launch_instances(
job=None,
nodes_to_launch={"queue1": {"c5xlarge": node_list}},
launch_batch_size=500,
scaling_strategy=scaling_strategy,
)

# 500 x 17 = 8500 fails; the batch and the remaining 100 nodes are relaunched in batches of 250 (4250)
assert_that(requested_counts).is_equal_to([500, 250, 250, 100])
assert_that(instances_launched["queue1"]["c5xlarge"]).is_length(600)
assert_that(instance_manager.failed_nodes).is_empty()

def test_launch_instances_stops_splitting_when_single_instance_exceeds_limit(self, mocker, instance_manager):
"""An instance alone over the limit fails its nodes with the EC2 error code; small batches are not split."""
requested_counts = self._mock_run_instances_with_network_interfaces(
mocker, network_interfaces_per_instance=17, max_per_request=16
)
node_list = [f"queue1-st-c5xlarge-{index}" for index in range(1, 501)]

instance_manager._launch_instances(
job=None,
nodes_to_launch={"queue1": {"c5xlarge": node_list}},
launch_batch_size=500,
scaling_strategy=ScalingStrategy.BEST_EFFORT,
)

# Batches of 50 nodes or fewer are not split: 4 splits down to 32, then the 500 nodes in batches of 32
assert_that(requested_counts).is_equal_to([500, 250, 125, 63] + [32] * 15 + [20])
assert_that(instance_manager.failed_nodes).is_equal_to({"AttachmentLimitExceeded": set(node_list)})

@pytest.mark.parametrize(
"job_list, launch_batch_size, assign_node_batch_size, update_node_address, "
"expected_single_nodes_no_oversubscribe, scaling_strategy",
Expand Down
Loading