$30 off During Our Annual Pro Sale. View Details »

自動スケールから始める EC2 スポットインスタンス

自動スケールから始める EC2 スポットインスタンス

2020年11月11日に開催した、「秋のスポットインスタンス祭り」での発表資料です。
https://pages.awscloud.com/JAPAN-event-OE-Spot-instance-Matsuri-20201111-reg-event-LP.html

Haruyoshi Takiguchi

November 11, 2020
Tweet

More Decks by Haruyoshi Takiguchi

Other Decks in Technology

Transcript

  1. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1
    アマゾンウェブサービスジャパン株式会社
    2020-11-11
    〜秋のスポットインスタンス祭り〜
    ⾃動スケールから始める EC2 スポットインスタンス

    View Slide

  2. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2
    ⾃⼰紹介
    滝⼝ 開資 (はるよし)
    ソリューションアーキテクト / EC2スポットインスタンススペシャリスト
    ⽇本市場でのEC2スポットインスタンス製品担当
    普段の業務
    EC2スポットインスタンスを活⽤するお客様を
    技術⾯からサポート
    好きなAWSサービス
    • Amazon EC2 Auto Scaling
    • AWS Support

    View Slide

  3. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 3
    本⽇の内容
    • ⾃動スケールとスポットインスタンスのユースケース
    • スポットインスタンス これだけは
    • EC2 Auto Scalingとスポットインスタンス 3つの重要ポイント

    View Slide

  4. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 4
    ⾃動スケールとスポットインスタンスの
    ユースケース

    View Slide

  5. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 5
    インフラのコスト
    時間
    ビジネスの需要予測
    ビジネス需要に応じたキャパシティ準備

    View Slide

  6. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 6
    インフラのコスト
    時間
    従来型ハードウェア
    ビジネス需要に応じたキャパシティ準備
    大規模な
    システム
    投資
    ビジネスの需要予測

    View Slide

  7. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 7
    実際の需要
    ビジネス需要に応じたキャパシティ準備
    大規模な
    システム
    投資
    インフラのコスト
    時間
    従来型ハードウェア

    View Slide

  8. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 8
    使わなかった
    部分
    ビジネス需要に応じたキャパシティ準備
    大規模な
    システム
    投資
    機会損失
    インフラのコスト
    時間
    実際の需要
    従来型ハードウェア

    View Slide

  9. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 9
    実際の需要
    実際のAWSリソース
    ビジネス需要に応じたキャパシティ準備
    Auto Scalingサービスなどの
    自動スケールする仕組みにより
    実際の需要に合わせたリソース調達が可能
    • 準備しすぎの無駄を極小化
    • 機会損失を極小化
    インフラのコスト
    時間

    View Slide

  10. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 10
    スポットインスタンスとはなにか 〜 Amazon EC2の購⼊オプション
    オンデマンドインスタンス
    ⻑期コミット無し、使⽤分への⽀払い
    (秒単位/時間単位)。Amazon EC2の定価
    スパイクするようなワーク
    ロード
    リザーブドインスタンス
    とSavings Plans
    1年/3年の⻑期コミットに応じた
    ⼤幅なディスカウント価格
    ⼀定の負荷の⾒通しがある
    ワークロード
    スポットインスタンス
    Amazon EC2の空きキャパシティを活
    ⽤し最⼤90%値引き。中断あり
    中断に強く、かつ様々な
    インスタンスタイプを活⽤
    できるワークロード
    EC2インスタンスとしての性能に違いはない

    View Slide

  11. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 11
    EC2購⼊オプションをどう組み合わせるか?
    ⼀定の負荷が⾒込めるワーク
    ロードには
    中断に強く、スケールするワーク
    ロードには
    新規のワークロード、あるいはス
    テートフルなワークロードには
    オンデマンドインスタンス

    View Slide

  12. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 12
    株式会社みらい翻訳様
    • ⽇英・⽇中、ファイル・テキスト等、
    多様な形式の翻訳を⾏う推論環境をAWSで実現
    • スポットインスタンス⽐率を100%にするため、
    従来のアプリケーションをコンテナ化。スポッ
    トインスタンスの中断に強いアーキテクチャを
    構築
    • Amazon EC2 Auto ScalingやAmazon ECS、各種
    サーバーレスサービスを活⽤。コンテナ、EC2
    インスタンス、アベイラビリティゾーン障害も
    考慮したサービス継続性の⾼い環境を最適な費
    ⽤で実現
    TOEIC960点レベルの⽇英翻訳、⼈⼿レベルの⽇中翻訳等の⾼精度な機械翻訳サービスをAWSで実現。
    ⾼い可⽤性、性能、セキュリティを保ちつつ、EC2 スポットインスタンスの活⽤で費⽤を最適化。
    疎結合な設計→耐障害性の向上→スポットインスタンスに最適

    View Slide

  13. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 13
    スポットインスタンスと他サービスとの連携
    AWS
    Batch
    Amazon
    EMR
    Amazon Elastic
    Container Service
    AWS
    CloudFormation
    Amazon
    SageMaker
    AWS
    Elastic Beanstalk
    EC2 Auto
    Scaling AWS Thinkbox
    Deadline
    AWS
    Fargate

    View Slide

  14. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 14
    スポットインスタンスと他サービスとの連携
    AWS
    Batch
    Amazon
    EMR
    Amazon Elastic
    Container Service
    AWS
    CloudFormation
    Amazon
    SageMaker
    AWS
    Elastic Beanstalk
    EC2 Auto
    Scaling AWS Thinkbox
    Deadline
    AWS
    Fargate

    View Slide

  15. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 15
    Webワークロード
    • ステートレス
    ⾃動スケールの効く典型的なユースケース
    ⼤規模計算処理ワークロード
    • ビッグデータ分析
    • ハイパフォーマンスコン
    ピューティング
    • 機械学習

    View Slide

  16. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 16
    Webワークロード
    • ステートレス
    ⾃動スケールの効く典型的なユースケース
    ⼤規模計算処理ワークロード
    • ビッグデータ分析
    • ハイパフォーマンスコン
    ピューティング
    • 機械学習
    • Amazon EC2 + EC2 Auto Scaling
    (+コンテナサービス)

    View Slide

  17. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 17
    Webワークロード
    • ステートレス
    ⾃動スケールの効く典型的なユースケース
    ⼤規模計算処理ワークロード
    • ビッグデータ分析
    • ハイパフォーマンスコン
    ピューティング
    • 機械学習
    • Amazon EC2 + EC2 Auto Scaling
    (+コンテナサービス)
    • AWS Batch
    • Amazon EMR
    • Amazon EC2 + EC2 Auto Scaling
    (+コンテナサービス)

    View Slide

  18. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 18
    Amazon EC2 + EC2 Auto
    Scaling
    Webワークロード
    • ステートレス
    ⾃動スケールの効く典型的なユースケース
    ⼤規模計算処理ワークロード
    AWS Batch Amazon EMR
    ビッグデータ分析
    ハイパフォーマンス
    コンピューティング
    機械
    学習
    • Amazon EC2 + EC2 Auto Scaling
    (+コンテナサービス)

    View Slide

  19. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 19
    ⼤規模計算処理ワークロードの技術選定
    Amazon EC2
    + Auto Scaling
    AWS Batch Amazon EMR
    特徴と主な⽤途 • フルスクラッチでの構築
    • オンプレミスで稼働する
    アプリケーションのマイ
    グレーション
    • 全て⾃前で管理
    • 汎⽤的な分散コンピューティング
    • マネージドサービス
    • データの分散処理に特化
    • 「マネージドフレームワーク」
    処理の仕組み • 任意の要件 • 分散処理のタスクに、どのような
    処理を割り当てるのか⾃分で定義
    する
    • データ分析フレームワークにデータ
    (のディレクトリ)を渡す。分散処理
    のタスクへの処理割り当ては、フ
    レームワークが⾃動的に⾏う
    おすすめの
    利⽤シーン
    • 任意の要件 • データの量、スキーマが決まって
    いる
    • パラメータの組を渡して少しずつ
    計算を変化させたい
    • データの量、スキーマが変動する可
    能性がある
    • ⼤量のログデータの変換・加⼯・分
    析をフレームワークに任せたい
    ランタイム環境 • 任意の要件 • コンテナ化が容易
    • 既存のライブラリ、⾔語フレーム
    ワークを使いたい
    • EMRのサポートするランタイム
    (Apache Hadoop, Apache Spark,
    Apache Hive, Prestoなど)を使いた

    費⽤の考慮点 • EC2インスタンスの料⾦ • 下回りのEC2インスタンスの料⾦
    • ジョブを制御する仕組みに費⽤が
    掛からない
    • 下回りのEC2インスタンスの料⾦ +
    EMR料⾦
    • ジョブを制御するマスターノードに
    も費⽤が掛かる

    View Slide

  20. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 25
    スポットインスタンス これだけは
    (2020年 圧縮版)

    View Slide

  21. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 26
    スポットインスタンス これだけは (2020年版)
    • いつ起動できるのか、いつ中断されるのか
    • 価格はどう決まるのか
    • ⼊札不要モデル :「⼊札はいりません」
    • 中断のハンドリング
    本⽇触れられなかったトピックはこちらをご視聴ください
    AWS-27:Amazon EC2 だけじゃない!最⾼のコスト効率を⼿に⼊れるためのスポットインスタンス使いこなし術
    https://resources.awscloud.com/aws-summit-online-japan-2020-on-demand-aws-sessions-2-45123/aws-27-aws-summit-online-2020-720p

    View Slide

  22. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 27
    スポットインスタンス これだけは (2020年版)
    • いつ起動できるのか、いつ中断されるのか
    • 価格はどう決まるのか
    • ⼊札不要モデル :「⼊札はいりません」
    • 中断のハンドリング

    View Slide

  23. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 28
    おさらい:EC2インスタンスのライフサイクル
    • AMIからインスタンス
    を起動
    • runningで使⽤開始
    • 使い終わったら終了指

    • terminatedでインスタン
    ス削除
    AMI

    View Slide

  24. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 32
    スポットインスタンスのライフサイクル
    • 終了に⾄る道筋
    • ユーザーによるインスタ
    ンス終了
    • EC2スポットサービスによ
    る中断
    • インスタンスは削除される
    (デフォルト動作)
    • 起動の流れはオンデマンド
    インスタンスと同⼀
    • ただし起動できないこと
    がある
    AMI

    View Slide

  25. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 33
    空きキャパシティとスポットプール (1)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    r5.large c5.large
    ap-northeast-1c
    m5.large

    r5.large c5.large

    View Slide

  26. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 34
    空きキャパシティとスポットプール (2)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    ap-northeast-1c
    m5.large

    c5.large
    使⽤中
    使⽤中
    使⽤中
    使⽤中
    r5.large
    使⽤中
    r5.large
    使⽤中

    View Slide

  27. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 35
    空きキャパシティとスポットプール (3)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    ap-northeast-1c
    m5.large

    c5.large
    使⽤中
    使⽤中
    使⽤中
    使⽤中
    r5.large
    使⽤中
    r5.large
    使⽤中
    スポットプール…リージョン、アベイラビリティゾーン(AZ),
    インスタンスタイプごとに独⽴した空きキャパシティ

    View Slide

  28. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 36
    空きキャパシティとスポットプール (5)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    使⽤中
    使⽤中
    r5.large
    使⽤中
    スポットプールに空きキャパシティがある→起動できる
    • 1aゾーンでは
    どのインスタンスタイプも
    空きキャパシティがある
    スポットインスタンスを
    起動できる

    View Slide

  29. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 37
    空きキャパシティとスポットプール (5)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    使⽤中
    使⽤中
    r5.large
    使⽤中
    スポットプールに空きキャパシティがない→起動できない
    • 1aゾーンでc5.largeの
    空きキャパシティが不⾜
    スポットインスタンスは
    起動できない

    View Slide

  30. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 38
    空きキャパシティとスポットプール (5)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    使⽤中
    使⽤中
    r5.large
    使⽤中
    スポットプールに空きキャパシティがある→起動できる
    • 1aゾーンでは
    どのインスタンスタイプも
    空きキャパシティがある
    スポットインスタンスを
    起動できる

    View Slide

  31. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 39
    空きキャパシティとスポットプール (5)
    ap-northeast-1a
    (Tokyo Region)
    m5.large

    c5.large
    使⽤中
    使⽤中
    r5.large
    使⽤中
    スポットプールに空きキャパシティがない
    →起動中のスポットインスタンスは中断される
    • 1aゾーンでc5.largeの
    空きキャパシティが不⾜
    スポットインスタンスは
    中断される

    View Slide

  32. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 40
    スポットインスタンス これだけは (2020年版)
    • いつ起動できるのか、いつ中断されるのか
    • EC2サービスに空きキャパシティがあれば起動できる
    • EC2サービスに空きキャパシティがなければ起動できない
    • EC2サービスに空きキャパシティが不⾜してくると中断される
    • 価格はどう決まるのか
    • ⼊札不要モデル :「⼊札はいりません」
    • 中断のハンドリング

    View Slide

  33. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 41
    スポットインスタンス これだけは (2020年版)
    • いつ起動できるのか、いつ中断されるのか
    • 価格はどう決まるのか
    • ⼊札不要モデル :「⼊札はいりません」
    • 中断のハンドリング

    View Slide

  34. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 42
    再掲:スポットインスタンスのライフサイクル
    • 起動の流れはオンデマンド
    インスタンスと同⼀
    • ただし起動できないこともある
    • 終了に⾄る道筋は2通り
    • ユーザーによるインスタンス終了
    • EC2スポットサービスによる中断
    • インスタンスは削除される
    (デフォルト動作)
    AMI

    View Slide

  35. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 43
    中断通知 - 2分前の通知
    • 中断の発⽣する2分前に
    「中断通知」を送付
    • 2分後にインスタンスは中断さ
    れる(デフォルトは削除)
    AMI

    View Slide

  36. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 44
    中断通知→すみやかに後処理を!!
    • 仕掛かり中の処理を退避す

    • 途中の計算結果をS3にアップ
    ロード
    • 新規処理の受付を停⽌する
    • ELBから登録解除
    • コンテナステータスをDRAINING

    2分間の活⽤が
    使いこなしのポイント
    AMI

    View Slide

  37. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 45
    スポットインスタンスのライフサイクル
    AMI
    • 中断の発⽣する2分前に
    「中断通知」を送付
    • 中断の予兆があれば、2分よ
    り早く「リバランス通知」
    を送付
    • あるスポットインスタンスの中
    断リスクが⾼まってきたとき、
    EC2サービスから「リバランス
    通知」が通知される
    • 2分前の中断通知に先んじて提
    供されることが多い
    New!!

    View Slide

  38. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 47
    スポットインスタンスアドバイザー
    https://aws.amazon.com/jp/ec2/spot/instance-advisor/

    View Slide

  39. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 48
    スポットインスタンスアドバイザー
    https://aws.amazon.com/jp/ec2/spot/instance-advisor/

    View Slide

  40. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 49
    スポットインスタンスアドバイザー
    https://aws.amazon.com/jp/ec2/spot/instance-advisor/

    View Slide

  41. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 50
    中断通知・リバランス通知 - 受信の2つの⽅法
    • インスタンスメタデータ
    • インスタンス内部からアクセス
    • 5秒おきのチェック(pull型)
    • 後処理
    • シェルスクリプトを書く
    • ⾃インスタンスのことなので⾃分の
    処理を記述
    • Amazon EventBridge
    (Amazon CloudWatch Event)
    • インスタンス外部からアクセス
    • ⾃動受信(push型)
    • 後処理
    • Lambda関数を書く
    • 中断対象のインスタンスをまず把握
    • 汎⽤的に記述
    シェルスクリプト
    S3に書き出し
    ELBから登録解除
    中断通知
    Lambda関数
    どのインスタンスか把握
    S3に書き出し
    ELBから登録解除
    Spot
    instance
    Event
    中断通知

    View Slide

  42. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 51
    EC2 Auto Scalingとスポットインスタンス
    3つの重要ポイント

    View Slide

  43. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 52
    スポットインスタンス活⽤のための
    EC2 Auto Scalingの3つの重要ポイント
    • ミックスインスタンスグループポリシー
    • capacity-optimized配分戦略
    • キャパシティリバランシング機能 ← New!!

    View Slide

  44. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 53
    Auto Scalingの新機能:ミックスインスタンスグループ以前
    m4.large Spot ASG Min: 1 Max: 10
    m5.large Spot ASG Min: 1 Max: 10
    c4.xlarge O-D ASG Min: 1 Max: 10
    Availability
    Zone 1
    Availability
    Zone 2
    Availability
    Zone 3
    以前の設計
    - オンデマンド⽤
    ASGとスポット
    ⽤ASGを別に⽤

    - 使⽤するインス
    タンスタイプご
    とにASGを⽤意
    ASG: Auto Scaling Group
    O-D: On Demand Instance

    View Slide

  45. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 54
    Auto Scalingの新機能:ミックスインスタンスグループ
    m4.large Spot Instances
    m5.large Spot Instances
    c4.xlarge On-Demand instances
    Availability
    Zone 1
    Availability
    Zone 2
    Availability
    Zone3
    現在の設計:単⼀
    のASGに複数購⼊
    オプションや複数
    のインスタンスタ
    イプを指定できる
    Single ASG
    ASG: Auto Scaling Group
    O-D: On Demand Instance
    RI: Reserved Instance

    View Slide

  46. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 55
    押さえておきたいAuto Scaling Groupのパラメーター

    View Slide

  47. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 56
    押さえておきたいAuto Scaling Groupのパラメーター

    View Slide

  48. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 57
    押さえておきたいAuto Scaling Groupのパラメーター
    ミックスインスタンス
    グループポリシー
    capacity-optimized
    配分戦略
    キャパシティ
    リバランシング機能

    View Slide

  49. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 58
    押さえておきたいAuto Scaling Groupのパラメーター
    ミックスインスタンス
    グループポリシー

    View Slide

  50. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 59
    押さえておきたいAuto Scaling Groupのパラメーター
    • 台数の考え⽅
    1. 全体数は「グループサイズ」(後ほど指定)
    2. そこから「オンデマンドベースのキャパシティ」の台数をオンデマンドで起動
    3. 残りを「ベース以上のオンデマンド割合」にしたがって分配

    View Slide

  51. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 60
    押さえておきたいAuto Scaling Groupのパラメーター
    • 台数の考え⽅
    1. 全体数は「グループサイズ」(後ほど指定)
    2. そこから「オンデマンドベースのキャパシティ」の台数をオンデマンドで起動
    3. 残りを「ベース以上のオンデマンド割合」にしたがって分配
    グループサイズ
    オプションのオンデマンド 「ベース以上」

    View Slide

  52. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 61
    押さえておきたいAuto Scaling Groupのパラメーター
    グループサイズ
    オプションのオンデマンド 70%=オンデマンド 30%=スポット
    • 台数の考え⽅
    1. 全体数は「グループサイズ」(後ほど指定)
    2. そこから「オンデマンドベースのキャパシティ」の台数をオンデマンドで起動
    3. 残りを「ベース以上のオンデマンド割合」にしたがって分配

    View Slide

  53. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 62
    押さえておきたいAuto Scaling Groupのパラメーター
    グループサイズ
    オプションのオンデマンド 70%=オンデマンド 30%=スポット
    オンデマンド台数 スポット台数
    • 台数の考え⽅
    1. 全体数は「グループサイズ」(後ほど指定)
    2. そこから「オンデマンドベースのキャパシティ」の台数をオンデマンドで起動
    3. 残りを「ベース以上のオンデマンド割合」にしたがって分配

    View Slide

  54. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 63
    複数のインスタンスタイプの指定

    View Slide

  55. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 64
    押さえておきたいAuto Scaling Groupのパラメーター
    capacity-optimized
    配分戦略

    View Slide

  56. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 65
    Auto Scalingグループの配分戦略
    配分戦略
    指定したインスタンスタイプから Auto Scaling グループがオ
    ンデマンド容量とスポット容量をどのように満たすかを決定
    する設定項⽬
    オンデマンドインスタンス:
    • prioritized のみ
    • マネジメントコンソール(やCLI⽤json)で上から定義し
    た順に、優先的に起動を試みる
    • 例: m4.large -> c4.large -> r4.largeの順に⽤いる
    • RIやSPを購⼊しているものを上位に記述するのが良い
    スポットインスタンス:
    • lowest-price
    • AZごとに、価格の安い順にN番⽬のプールまでを対象に起動を
    試みる
    • capacity-optimized
    • 空きキャパシティの余裕に応じて最適なスポットプールを⾃動
    的に選択し、起動を試みる

    View Slide

  57. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 66
    Auto Scalingグループのcapacity-optimized配分戦略
    us-east-1a
    Desired capacity: 12
    SpotAllocationStrategy: capacity-optimized
    OnDemandBaseCapacity: 0 OnDemandPercentageAboveCapacity: 0
    r5.large
    m4.large
    m5.large
    r5.large
    m4.large
    m5.large
    r5.large
    m4.large
    m5.large
    R5 R5
    R5 R5
    $$
    $
    $$$
    $$
    $$$
    $
    $$$
    $
    $$
    us-east-1b us-east-1c
    Overrides: [“r5.large”, “m4.large”, ”m5.large”]
    ⼤変オススメです

    View Slide

  58. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 68
    EC2 Auto Scalingでのcapacity-optimizedの指定
    capacity-optimized
    配分戦略
    • 起動⽅法によりデフォルト動作が異なる
    • マネジメントコンソール:capacity-optimizedがデフォルト
    • API (CLIやSDKなど):lowest-priceがデフォルト(最安値を選択する)

    View Slide

  59. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 69
    押さえておきたいAuto Scaling Groupのパラメーター
    キャパシティ
    リバランシング機能

    View Slide

  60. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 70
    キャパシティリバランシング機能
    • Amazon EC2「リバランス通知」
    • あるスポットインスタンスの中断リスクが⾼まってきたとき、EC2
    サービスから「リバランス通知」が通知される
    • 2分前の中断通知に先んじて提供されることが多い
    • EC2 Auto Scaling「キャパシティリバランシング機能」
    • Auto Scalingグループ内のスポットインスタンスに「リバランス通
    知」が送付されるとき、次の動作を取る
    • 先に新規スポットインスタンスを起動
    • ヘルスチェックに合格した後、中断可能性ありとマークされたスポットイン
    スタンスを削除
    • ロードバランサーへの登録・登録解除も⾃動的に実施される
    ←New!!
    ←New!!
    アップデート — EC2 Auto Scalingのキャパシティリバランシング機能によるスポットインスタンスの事前置き換え | Amazon Web Services ブログ
    https://aws.amazon.com/jp/blogs/news/proactively-manage-spot-instance-lifecycle-using-the-new-capacity-rebalancing-feature-for-ec2-auto-scaling/

    View Slide

  61. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 71
    押さえておきたいAuto Scaling Groupのパラメーター
    ミックスインスタンス
    グループポリシー
    capacity-optimized
    配分戦略
    キャパシティ
    リバランシング機能

    View Slide

  62. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 72
    スポットプールの分散のヒント (1)
    • インスタンスタイプ・アベイラビリティゾーンを
    複数選択する→中断に対するリスクを分散できる
    • インスタンスタイプ選定の⼀般論:
    近いインスタンスタイプを選ぶ + 1世代前を選ぶ
    • m5.large (2 vCPU, 8GB, $0.13/h)が使える
    • c5.large (2 vCPU, 4 GB, $0.11/h), r5.large (2 vCPU, 16GB, $0.15/h)を候補
    にする
    • m4.large (2 vCPU, 8GB, 0.13/h)を候補にする (+c4.large, r4.large)
    価格は2020年2⽉21⽇現在、東京リージョンでのオンデマンドインスタンスのもの

    View Slide

  63. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 73
    スポットプール分散のヒント (2)
    Amazon EC2 Instance Selector
    • インスタンスタイプ選定のためのヘルパーツール(CLI)
    • https://github.com/aws/amazon-ec2-instance-selector

    View Slide

  64. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 74
    本⽇のまとめ

    View Slide

  65. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 75
    本⽇のまとめ
    • ⾃動スケールとスポットインスタンスのユースケース
    • Webワークロード、⼤規模処理ワークロード
    • 技術選定のポイント
    • スポットインスタンス これだけは
    • いつ起動できるのか、いつ中断されるのか
    • 中断のハンドリング
    • EC2 Auto Scalingとスポットインスタンス 3つの重要ポイント
    • ミックスインスタンスグループポリシー
    • capacity-optimized配分戦略
    • キャパシティリバランシング機能

    View Slide

  66. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 76
    Thank you!

    View Slide