ポリシータイプ比較

ASG の動的スケーリングには3つのポリシータイプがある。

  Simple Scaling Step Scaling Target Tracking
調整量 固定(例: +1台) 段階的(例: 80%→+1, 90%→+2) 自動(AWS が計算)
cooldown あり(その間スケーリング不可) なし(連続対応可) 自動管理
設定の手間 低(閾値+台数を指定) 中(段階を定義) 低(目標値のみ)
同一ASGに設定可能な数 制限なし 制限なし 最大4つ
カスタムメトリクス対応
AWS の推奨 レガシー 必要時のみ 推奨

Simple Scaling

閾値を超えたら固定の台数を増減する。cooldown 期間中はスケーリングが発生しない。

CPU ≥ 80% → +1台(cooldown: 300秒)
CPU < 10% → -1台(cooldown: 300秒)

Step Scaling

閾値の超過幅に応じて段階的に調整量を変える。cooldown なしで連続的に反応できる。

CPU 80〜90% → +1台
CPU 90〜95% → +2台
CPU 95%〜   → +3台

Target Tracking

目標値を設定するだけで、AWS が自動的に台数を調整する。サーモスタットのように動作する。

CPU の目標値 = 70% を維持(AWS が自動調整)

複数ポリシーの併用時の挙動

1つの ASG に複数のスケーリングポリシーを設定できる。例えば CPU ベースのポリシーとカスタムメトリクスベースのポリシーを並行運用する場合など。

AWS の動作ルール(固定、変更不可)

“When these situations occur, Amazon EC2 Auto Scaling chooses the policy that provides the largest capacity for both scale out and scale in.”

Dynamic scaling for Amazon EC2 Auto Scaling

操作 AWS の動作 意味
scale-out 最大のキャパシティ変更を採用 最も多く増やすポリシーが優先
scale-in 最大のキャパシティ(=最も台数を残す)を採用 最も削除が少ないポリシーが優先

設計思想: 常に「台数が多くなる方向」に倒れる(可用性 > コスト最適化)。

scale-out の例

“Suppose, for example, that the policy for CPUUtilization launches one instance, while the policy for the SQS queue launches two instances. If the scale-out criteria for both policies are met at the same time, Amazon EC2 Auto Scaling gives precedence to the SQS queue policy. This results in the Auto Scaling group launching two instances.”

scale-in の例

“The approach of giving precedence to the policy that provides the largest capacity applies even when the policies use different criteria for scaling in. For example, if one policy terminates three instances, another policy decreases the number of instances by 25 percent, and the group has eight instances at the time of scale in, Amazon EC2 Auto Scaling gives precedence to the policy that provides the largest number of instances for the group. This results in the Auto Scaling group terminating two instances (25 percent of 8 = 2). The intention is to prevent Amazon EC2 Auto Scaling from removing too many instances.”

結果: 自動的に OR / AND 動作になる

2つのポリシー(A と B)を設定した場合、以下の動作になる。

状況 ポリシーA ポリシーB 結果
A だけ scale-out 条件 +1台 何もしない +1台(OR: どちらかが高ければ追加)
B だけ scale-out 条件 何もしない +1台 +1台(OR: どちらかが高ければ追加)
両方 scale-out 条件 +1台 +1台 +1台(最大を採用)
両方 scale-in 条件 -1台 -1台 -1台(AND: 両方低い場合のみ縮小)
A だけ scale-in 条件 -1台 何もしない 何もしない(AND: 片方がまだ高い)
B だけ scale-in 条件 何もしない -1台 何もしない(AND: 片方がまだ高い)

つまり:

  • スケールアウト: どちらか一方の閾値を超えれば発動 = OR
  • スケールイン: 両方の閾値を下回った場合のみ発動 = AND

この挙動は AWS の固定仕様であり、設定で変更することはできない。

ポリシータイプ混在時の注意

“We recommend caution, however, when using target tracking scaling policies with step scaling policies because conflicts between these policies can cause undesirable behavior. For example, if the step scaling policy initiates a scale in activity before the target tracking policy is ready to scale in, the scale in activity will not be blocked.”

異なるポリシータイプを混在させると予期しない挙動が発生する可能性がある。同じタイプで揃えるのが安全。

参考