

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Slurm 集群快速容量不足故障转移
<a name="slurm-short-capacity-fail-mode-v3"></a>

从 AWS ParallelCluster 版本 3.2.0 开始，集群在默认情况下会启用快速容量不足故障转移模式。这会最大限度地减少检测到 Amazon EC2 容量不足错误时对作业重试排队所花费的时间。当您将队列配置为使用不同实例类型的多个计算资源时，这尤其有效。

**Amazon EC2 检测到容量不足故障：**
+ `InsufficientInstanceCapacity`
+ `InsufficientHostCapacity`
+ `InsufficientReservedInstanceCapacity`
+ `MaxSpotInstanceCountExceeded`
+ `SpotMaxPriceTooLow`：竞价型请求价格低于要求的最低竞价型请求履行价格时激活。
+ `Unsupported`：使用特定实例类型不支持的实例类型激活 AWS 区域。

在快速容量不足故障切换模式下，如果在将任务分配给 [`SlurmQueues`](Scheduling-v3.md#Scheduling-v3-SlurmQueues)/时检测到容量不足错误 [`compute resource`](Scheduling-v3.md#Scheduling-v3-SlurmQueues-ComputeResources)，则 AWS ParallelCluster 执行以下操作：

1. 将计算资源设置为禁用 (`DOWN`) 状态，持续预定义的时间段。

1. 使用 `POWER_DOWN_FORCE` 取消计算资源失败的节点作业并暂停失败的节点。将失败的节点设置为 `IDLE` 和 `POWER_DOWN (!)` 状态，然后设置为 `POWERING_DOWN (%)`。

1. 将作业重新排队到另一个计算资源。

已禁用计算资源的静态和已启动的节点不受影响。作业可以在这些节点上完成。

此循环将会重复，直到将作业成功分配给一个或多个计算资源节点。有关节点状态的信息，请参阅 [Slurm 多队列模式指南](multiple-queue-mode-slurm-user-guide-v3.md)。

如果找不到运行该作业的计算资源，则将作业设置为 `PENDING` 状态，直到经过预定义的时间段。在这种情况下，您可以按照下一节所述修改预定义时间段。

## 容量不足超时参数
<a name="slurm-short-capacity-fail-mode-parameter-v3"></a>

**`insufficient_capacity_timeout`**

`insufficient_capacity_timeout` 指定检测到容量不足错误时，计算资源保持在禁用 (`down`) 状态的时间段（以秒为单位）。

默认情况下，`insufficient_capacity_timeout` 处于启用状态。

默认的 `insufficient_capacity_timeout` 为 600 秒（10 分钟）。

如果 `insufficient_capacity_timeout` 值小于或等于零，则表示已禁用快速容量不足故障转移模式。

通过在 `HeadNode` 中 `/etc/parallelcluster/slurm_plugin/parallelcluster_clustermgtd.conf` 处的 `clustermgtd` 配置文件中添加该参数，可以更改 `insufficient_capacity_timeout` 值。

可以在不停止计算实例集的情况下随时更新该参数。

例如：
+ `insufficient_capacity_timeout=600`:

  如果检测到容量不足错误，则会将计算资源设置为禁用 (`DOWN`)。10 分钟后，其失败节点将设置为 `idle~` (`POWER_SAVING`) 状态。
+ `insufficient_capacity_timeout=60`:

  如果检测到容量不足错误，则计算资源将处于禁用状态 (`DOWN`)。1 分钟后，其失败节点将设置为 `idle~` 状态。
+ `insufficient_capacity_timeout=0`:

  禁用了快速容量不足故障转移模式。未禁用计算资源。

**注意**  
从节点因容量不足错误而失败到集群管理进程守护程序检测到节点失败之间可能有长达一分钟的延迟。这是因为集群管理守护程序会检查节点容量不足故障，并每隔一分钟将计算资源设置为`down`状态。

## 快速容量不足故障转移模式状态
<a name="slurm-short-capacity-fail-mode-status-v3"></a>

当集群处于快速容量不足故障转移模式时，您可以检查其状态和节点状态。

### 节点状态
<a name="slurm-short-capacity-fail-mode-nodes-v3"></a>

当作业提交到计算资源动态节点并检测到容量不足错误时，该节点将被置于 `down#` 状态并显示原因：

```
(Code:InsufficientInstanceCapacity)Failure when resuming nodes.
```

然后，关闭的节点（处于 `idle~` 状态的节点）将被设置为 `down~` 并显示原因：

```
(Code:InsufficientInstanceCapacity)Temporarily disabling node due to insufficient capacity.
```

作业重新排队到队列中的其他计算资源。

计算资源静态节点和处于 `UP` 状态的节点不受快速容量不足故障转移模式影响。

请考虑以下示例中所示的节点状态。

```
$ sinfo
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST
queue1*   up    infinite    30  idle~ queue1-dy-c-1-[1-15],queue1-dy-c-2-[1-15]
queue2    up    infinite    30  idle~ queue2-dy-c-1-[1-15],queue2-dy-c-2-[1-15]
```

我们向 queue1 提交了需要一个节点的作业。

```
$ sinfo
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST
queue1*   up   infinite  1   down# queue1-dy-c-1-1
queue1*   up   infinite  15  idle~ queue1-dy-c-2-[1-15]
queue1*   up   infinite  14  down~ queue1-dy-c-1-[2-15]
queue2    up   infinite  30  idle~ queue2-dy-c-1-[1-15],queue2-dy-c-2-[1-15]
```

节点 `queue1-dy-c-1-1` 将会启动以运行该作业。但由于容量不足错误，该实例启动失败。节点 `queue1-dy-c-1-1` 被设置为 `down`。该计算资源中已关闭的动态节点 (`queue2-dy-c-1`) 将被设置为 `down`。

您可以使用 `scontrol show nodes` 检查节点原因。

```
$ scontrol show nodes queue1-dy-c-1-1
NodeName=broken-dy-c-2-1 Arch=x86_64 CoresPerSocket=1 
CPUAlloc=0 CPUTot=96 CPULoad=0.00
...
ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s
Reason=(Code:InsufficientInstanceCapacity)Failure when resuming nodes [root@2022-03-10T22:17:50]
   
$ scontrol show nodes queue1-dy-c-1-2
NodeName=broken-dy-c-2-1 Arch=x86_64 CoresPerSocket=1 
CPUAlloc=0 CPUTot=96 CPULoad=0.00
...
ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s
Reason=(Code:InsufficientInstanceCapacity)Temporarily disabling node due to insufficient capacity [root@2022-03-10T22:17:50]
```

作业排队到队列计算资源中的另一种实例类型。

经过 `insufficient_capacity_timeout` 之后，计算资源中的节点将重置为 `idle~` 状态。

```
$ sinfo
PARTITION AVAIL TIMELIMIT NODES STATE NODELIST
queue1*   up    infinite    30  idle~ queue1-dy-c-1-[1-15],queue1-dy-c-2-[1-15]
queue2    up    infinite    30  idle~ queue2-dy-c-1-[1-15],queue2-dy-c-2-[1-15]
```

经过 `insufficient_capacity_timeout` 并且计算资源中的节点重置为 `idle~` 状态后，Slurm 调度器会为这些节点分配较低的优先级。除非发生以下情况之一，否则调度器会继续从其他队列计算资源中选择权重较高的节点：
+ 作业的提交要求与已恢复的计算资源相匹配。
+ 没有其他计算资源可用，因为它们的容量已满。
+ `slurmctld` 已重新启动。
+  AWS ParallelCluster 计算队列已停止并开始关闭所有节点的电源并开启电源。

### 相关日志
<a name="slurm-protected-mode-logs-v3"></a>

可以在头节点的 Slurm `resume` 日志和 `clustermgtd` 日志中找到与容量不足错误和快速容量不足故障转移模式相关的日志。

**Slurm `resume` (`/var/log/parallelcluster/slurm_resume.log`)**  
节点由于容量不足而无法启动时的错误消息。  

```
[slurm_plugin.instance_manager:_launch_ec2_instances] - ERROR - Failed RunInstances request: dcd0c252-90d4-44a7-9c79-ef740f7ecd87
[slurm_plugin.instance_manager:add_instances_for_nodes] - ERROR - Encountered exception when launching instances for nodes (x1) ['queue1-dy-c-1-1']: An error occurred 
(InsufficientInstanceCapacity) when calling the RunInstances operation (reached max retries: 1): We currently do not have sufficient p4d.24xlarge capacity in the 
Availability Zone you requested (us-west-2b). Our system will be working on provisioning additional capacity. You can currently get p4d.24xlarge capacity by not 
specifying an Availability Zone in your request or choosing us-west-2a, us-west-2c.
```

**Slurm `clustermgtd` (`/var/log/parallelcluster/clustermgtd`)**  
queue1 中的计算资源 c-1 因容量不足而被禁用。  

```
[slurm_plugin.clustermgtd:_reset_timeout_expired_compute_resources] - INFO - The following compute resources are in down state 
due to insufficient capacity: {'queue1': {'c-1': ComputeResourceFailureEvent(timestamp=datetime.datetime(2022, 4, 14, 23, 0, 4, 769380, tzinfo=datetime.timezone.utc), 
error_code='InsufficientInstanceCapacity')}}, compute resources are reset after insufficient capacity timeout (600 seconds) expired
```
容量不足超时到期后，将会重置该计算资源，并将计算资源中的节点设置为 `idle~`。  

```
[root:_reset_insufficient_capacity_timeout_expired_nodes] - INFO - Reset the following compute resources because insufficient capacity 
timeout expired: {'queue1': ['c-1']}
```