# Startup Rules

## Definitions of Hosts

Healthy Hosts

> Definition: Hosts that are operating normally and have passed health checks.
> 
> Characteristics:
> - Host status is "Normal".
> - Have passed the health check of ULB.

Initializing Hosts

> Definition: Hosts that are starting up, being configured, or newly created but not fully ready yet.
> 
> Characteristics:
> - Host status is "Initializing".
> - Host status is "Normal" but hasn’t passed the health check, and the creation time is within the predefined cooling period.

Unhealthy Hosts

> Definition: Hosts that have completed initialization but failed to pass the health check.
> 
> Characteristics:
> - Host status is "Normal".
> - Failed the ULB health check, and the creation time exceeds the predefined cooling period.

## Host Quantity Range Rules

- Target 1 (Scaling Up Logic): Healthy Hosts + Initializing Hosts ≥ Minimum Quantity
- Target 2 (Scaling Down Logic): Healthy Hosts + Initializing Hosts + Unhealthy Hosts ≤ Maximum Quantity
- When scaling up (triggered by Target 1), check if the post-scaling host count meets Target 2; cancel scaling up if not.

## CPU Rules

- Processing is only performed when CPU metric calculations indicate a need to change the number of hosts.
- Ensure the post-change host count does not violate the minimum/maximum limits.
- Scaling quantity calculation formula: delta = (AvgGroupCPU * ActiveCount / cpuExpected) - ActiveCount.
> - When scaling up (delta > 0), exclude initializing hosts: delta = max(delta - InitCount, 0)
> - Scaling quantity (delta ≠ 0) must not exceed the host quantity range.

## Health Rules

1. Record the number of unhealthy hosts every two minutes.
2. Hosts recorded as unhealthy for three consecutive times will be removed.

Notes:
1. Hosts with removal protection enabled will not be deleted by the rules.
2. During downsizing, earlier created hosts and those automatically created by the scaling group will be removed first.

