Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SmartNewsにおける 1000+ノード規模 K8s基盤 でのコスト最適化 – Spot・...

SmartNewsにおける 1000+ノード規模 K8s基盤 でのコスト最適化 – Spot・Gravitonの大規模導入への挑戦

Avatar for ishikawa ryu

ishikawa ryu

July 02, 2025
Tweet

More Decks by ishikawa ryu

Other Decks in Technology

Transcript

  1. Copyright © SmartNews, Inc. All rights reserved. Self Introduction Yu

    Hu Senior Software Engineer Infrastructure Ryu Ishikawa Senior Software Engineer Product
  2. Copyright © SmartNews, Inc. All rights reserved. Agenda • What

    is SmartNews? • Background o Cost efficiency comes necessary and urgent o Savings Plans and Reserved Instance are not sufficient • Platform-Led Initiatives o Challenges o Solutions o Outcomes • Product Team's Success Story
  3. MISSION 世界中の良質な情報を 必要な人に送り届ける What is SmartNews ? : Partnership with

    AWS 1000+ノード規模のクラスタを複数運用 Amazon EKS を国内有数の規模で活用 その上に、AWSのマネージドサービスと社内でホストしたOSSを 組み合わせて多種多様な社内プラットフォームを構築 Ex: Flink/Spark/Trino/Hive/Kafka/ClickHouse/Milvus/TF Serving, etc マルチリージョン構成、Amazon EC2 Spot Instances や AWS Graviton の 活用、他発展的技術をAWSエキスパートと協働しながら最大限活用 🙌 AWS利用開始 Launch Spot・Graviton の活用 2025 EKSの導入 2020 マネージド サービス活用拡大 2015
  4. Copyright © SmartNews, Inc. All rights reserved. Background: Cost Increasing

    2024年1月、ある部門で予算の156%のシステムコストが発生 2024/01/01の予算 2024/01/01の実際のコスト 56% over 💸 Total Group A Group B
  5. Copyright © SmartNews, Inc. All rights reserved. • 不定期かつ大規模なAuto-Scaling •

    多くの並列新機能開発 • 多くの並列A/Bテスト • etc… Savings Plans と Reserved Instance では我々のワークロードには不十分 Background: Cost Increasing スタートアップとして柔軟性を維持しつつ、 より動的なコスト最適を実現するには? How we are • 柔軟なキャパシティの調整 • 安定したキャパシティの確保 So…
  6. Copyright © SmartNews, Inc. All rights reserved Copyright © SmartNews,

    Inc. All rights reserved Platform-Led Initiatives 10
  7. Copyright © SmartNews, Inc. All rights reserved. 要件やサービス特性 Ideas 大きなトラフィックの波

    ❏ 異なるサービスは異なるInstance Type/Familyを必要とする ❏ 高いパフォーマンスと低いレイテンシーのためには最新世代のインスタンスを使いたい ❏ 様々な時間間隔で、巨大なトラフィックの波が生じる 104 のインスタンスタイプ
  8. Copyright © SmartNews, Inc. All rights reserved. Ideas Savings Plans

    Amazon Relational Database Service (Amazon RDS) Amazon ElastiCache Surge Spot Instance K8s workload nodes Base Managed Service K8s computing resources Graviton Instance Reserved Instance On-Demand Instance Intel/AMD/ Graviton Instance Platformとしての方針
  9. Copyright © SmartNews, Inc. All rights reserved. Ideas 1000+ ノード規模のEKSクラスタ上に

    20+ チームの管理する 100+ サービスがある中で、 Spot Instance や Graviton の活用促進は簡単ではない。 しかし...
  10. Copyright © SmartNews, Inc. All rights reserved. Challenges ❏ ユーザー(≒社内エンジニア)教育

    ❏ Spot Instanceにまつわる不安を払拭 ❏ Spot Instanceを使う動機づけ
  11. Copyright © SmartNews, Inc. All rights reserved. ❏ Spot Instanceの中断や、

    キャパシティ不足エラーによる影響の 緩和策を実装 Challenges
  12. Copyright © SmartNews, Inc. All rights reserved. ❏ “The Engineering

    Triangle” の理解を醸成 ❏ Spotの中断に際して2分間の猶予があることを周知 ❏ サービスに影響があったかどうかがわかるように SLOを定義 ❏ Spot Capacity Poolのサイズを大きくすることで(>20)、 キャパシティは安定することを周知 ❏ AWSにおいてGravitonが幅広く使われており、 その性能とコスト面での利点を解説 Solutions: Knowledge Awareness AWSエキスパートと協働で社内セッションを開催 Fast Cheap Reliable Low Reliability More $$ Slow
  13. Copyright © SmartNews, Inc. All rights reserved. ❏ サービスごとのSpot vs.

    On-Demand 利用比率 ❏ サービスごとの時間単位コスト ❏ Spotの割引率 ❏ Spotの時間別/日別 中断回数 ❏ Spotのキャパシティ不足イベント回数 ❏ K8s/PodsのPending 時間 Solutions: Visibility Spot Instance と Graviton の活用を促すダッシュボードの構築
  14. Copyright © SmartNews, Inc. All rights reserved. Solutions: Visibility システムごとのSpot

    vs. On-Demand 利用比率を可視化 いくつのCPUコアがSpotまたはOn-Demandのインスタンスから 供給されているかをリアルタイム把握
  15. Copyright © SmartNews, Inc. All rights reserved. Solutions: Visibility aws-price-exporter

    Prometheus Recording rules Generate Prometheus AWS price Metrics Calculate the Accounted Cpu an Cost with Pod Level cpu/memory: 4 cores / 16G Pod1: 3 cores / 4G Pod2: 1 cores / 12G Pod-i Accounted Cost = max(cpuᵢ, memᵢ / r) / Σᵢ max(cpuᵢ, memᵢ / r) * Node Cost Pod1 50% Pod2 50% コストの分配
  16. Copyright © SmartNews, Inc. All rights reserved. Karpenterを使いスケーリング性能を向上 Spot Instanceの中断やキャパシティ不足の緩和

    Solutions Instance Typeを適切に選ぶポリシーの実装 高度なSpot枯渇時のFallbackの実装
  17. Copyright © SmartNews, Inc. All rights reserved. ❏ AWSの Spot

    Instance Advisorから利用可能なInstance Typeを確認 ❏ 中断の頻度とコストを見ながら適切なタイプを選択 ◦ 中断の頻度 < 15% ◦ オンデマンドと比較した費用削減 > 50% Solutions: Use selected instance types その結果Capacity insufficient イベントは大きく減少 Spotの入手可能性とコストのバランス
  18. Copyright © SmartNews, Inc. All rights reserved. Solutions: Use selected

    instance types Run as Job weekly 自動的にコスト・入手可能性の最適なバランスを取れるよう仕組み化 ❏ この仕組みは主にCluster Autoscalerを対象 ❏ Karpenterではprice-capacity-optimizedを 利用可能 ◦ 中断率とキャパシティの問題は 大幅に改善されている ❏ しかし、多少価格が高くなっても、より 安定性を求める特別なケースに対応する ために、この仕組みを活用
  19. Copyright © SmartNews, Inc. All rights reserved. Cluster Autoscaler: CAはAWS

    Auto Scaling Group(ASG)に依存して新しいインスタンスをプ ロビジョニングするため、スケールアップに数分かかる。 この遅延の主な原因は、AWSが新しいインスタンスをプロビジョニングし 、それらのインスタンスがクラスタ内で準備完了になるまでに時間がかか るため。 Karpenter: Karpenterは多くの場合、1分以内にインスタンスをプロビジョニングでき るほど、はるかに迅速にスケールアップするように設計されている。 これは、KarpenterがEC2 APIと直接やり取りし、より遅いASGメカニズ ムをバイパスするため。 Solutions: Use Karpenter to improve scaling performance https://www.nops.io/blog/karpenter-vs-cluster-autoscaler-vs-nks/ EC2 APIと直接やりとり インスタンス立ち上げのために Auto Scaling Group (ASG)に依存 スポットインスタンスを採用する上で、スケールアップのパフォーマン スは非常に重要. なぜなら、中断の通知は2分前にしか来ず、Fallbackの 時間を考慮する必要があるため。 Cluster AutoscalerからKarpenterへの移行
  20. Copyright © SmartNews, Inc. All rights reserved. スケーリングにかかる時間の短縮に成功 サービス全体の 安定性を向上

    Solutions: Use Karpenter to improve scaling performance Spot中断に備え 時間短縮 6 Minutes 3 Minutes OSSであるKarpenterを独自でカスタマイズし、効率と安定性を更に向上 ❏ スケールダウンのトリガーとして “利用率” を指定 ❏ 直近3分以内に配置されたPending状態のPodsはスケーリング計画の計算から除外 ❏ Spot Instance中断が発生した際には、即座にNodeClaimsを作成 NodeClaimsの 繰り返し作成を回避
  21. Copyright © SmartNews, Inc. All rights reserved. ❏ 明示的にSpot Instanceを指定できない

    ❏ どのNodeGroups/NodePoolsを使うかをPriorityでコントロール ❏ その結果、徐々にOn-Demand上でより多くのPodが実行される ❏ Node affinity Preferも使えるが、それは新規のnode作成を引き起こさない Karpenter/CA Solutions: Spot Fallback architecture: arm Generation: 8 Node Selector pricing: spot architecture: arm Generation: 8 Priority: 90 Node Group/Pool pricing: ondmd architecture: arm Generation: 8 Priority: 80 Launch Node Node Group/Pool Karpenter / CA Matching Node Success Failed Success 一般的なSpot InstanceのFallback
  22. Copyright © SmartNews, Inc. All rights reserved. Karpenter/CA pricing: spot

    architecture: arm Generation: 8 Weight: 80 expireAfter: 1h capacityType=ON_DE MAND Success ❏ 明示的にSpot Instanceを指定できる ❏ Fallback先のOn-Demandインスタンスは一定間隔で停止 Solutions: Spot Fallback pricing: spot architecture: arm Generation: 8 Node Selector pricing: spot architecture: arm Generation: 8 Weight: 90 Node Pool Launch Node Karpenter Matching Node Success Capacity Failed Check capacity again with a fixed interval Ensure Capacity Keep Cost Efficiency Karpenterの機能を利用: spec.expireAfter: 1h; spec.terminationGracePeriod: 5m 最大限Spotを活用するよう適切にコントロールされたFallback Node Pool
  23. Copyright © SmartNews, Inc. All rights reserved. Solutions: Seamless migration

    システム重要度 選択基準 Spot Instanceへの適性 Critical System トランザクション実行時間 < 30秒 (e.g., オンラインサービスの応答時間 < 1秒) ✅ 適合 – 実行時間が2分より短ければ、Spot中断による 処理の強制停止を回避できる トランザクション実行時間 > 2分 (e.g. 時間のかかるオフラインジョブ) ❌ 不適合 – 処理中に強制停止されうる Pod起動時間 < 1分 ✅ 適合 – 再起動しても即座にリカバリできる Pod起動時間 > 1分 & 10+レプリカ ✅ 許容 – 起動に時間がかかるとしても、 レプリカが相当数あれば強制停止の影響を緩和可能 Non-Critical System (特に基なし) ✅ 適合 – 早速Spot Instanceを導入 移行するサービスの選定基準
  24. Copyright © SmartNews, Inc. All rights reserved. ❏ 優れたパフォーマンス ❏

    低いコスト ❏ Intel, AMD, Gravitonのより潤沢なキャパシティを実現 Gravitonもサポートするためにマルチプラットフォームイメージを活用 Solutions: Seamless migration m6g.8xlarge: $0.3955 hourly m6i.8xlarge: $0.5882 hourly m6a.8xlarge: $0.6439 hourly.
  25. Copyright © SmartNews, Inc. All rights reserved. Solutions: Seamless migration

    Application Load Balancer (ALB) Spot On-Demand 30% 70% Scale in/out for Surge Base Usage Spot/On-Demandを組み合わせたK8s/Deployment定義
  26. Copyright © SmartNews, Inc. All rights reserved. Spot InstanceのNodeGroups/NodePoolsがデフォルトに Outcome

    >50% spot usage for monitoring system >80% spot usage for ranking system 100% spot usage for tensorflow serving 高いSpot Instanceの利用率を達成
  27. Copyright © SmartNews, Inc. All rights reserved. 100% Gravitonで実行 Outcome

    Gravitonの利用率も大きく向上させることに成功 ワークロードの40%強がGravitonを使用
  28. Copyright © SmartNews, Inc. All rights reserved. Takeaways ❏ 正しい認識を醸成し、簡単にコストを把握できるようにする

    ❏ Spot中断頻度とコスト削減の幅の適切なバランスをとる ❏ Karpenterを活用してスケーリングパフォーマンスを追求する ❏ Spotのキャパシティ不足に備えてフォールバックの仕組みを作り込む ❏ Gravitonを活用して、Spot活用によるコスト削減に加え 更に10%のコスト削減とより安定したキャパシティの実現を狙う
  29. Copyright © SmartNews, Inc. All rights reserved. Three Key actions

    コスト削減に集中するタスクフォースを組成 1 計測よりはじめよ 2 基本的な施策を愚直に進める 3
  30. Copyright © SmartNews, Inc. All rights reserved. Action1: Made a

    task-force team dedicated to cost reduction コスト削減に特化したチームとPICを明確に決めることは改めて重要
  31. Copyright © SmartNews, Inc. All rights reserved. Action2: Measurement comes

    first ダッシュボードは灯台。打ち手と推進力の源泉
  32. Copyright © SmartNews, Inc. All rights reserved. Action2: Measurement comes

    first コスト構造把握のための十分な投資は不可欠 https://docs.aws.amazon.com/cur/latest/userguide/what-is-cur.html 例: Amazon S3の共有バケットのprefixごとのコスト、社内プラットフォームの コンピュテーションコストなどをチームレベルで分解可能
  33. Copyright © SmartNews, Inc. All rights reserved. Action2: Measurement comes

    first 正しいコスト構造の理解は正しい打ち手を導く Div X Group A Group B offline srv
  34. Copyright © SmartNews, Inc. All rights reserved. Action3: Follow the

    very basic strategies “Quick Win Optimization” EC2 : PurchasePlanの見直し S3 : LifeCycleRuleの見直し 不要なコンポーネントの削除 https://aws.amazon.com/jp/blogs/news/aws-cost-optimization-guidebook/ AWSコスト最適化ガイドブック offline srv
  35. Copyright © SmartNews, Inc. All rights reserved. Success Story: Outcome

    結果として、適正なコストレベルにまで戻し、そこで安定させることに成功 45% down 🎉 Total Group A Group B 2024/03/31の実際のコスト 2024/03/31の予算 2024/01/01の実際のコスト
  36. Copyright © SmartNews, Inc. All rights reserved. Next Actions コスト改善をワンショットで終わらせてはいけない

    コスト説明 なぜ・何にコストがかかっているかを細かい粒度で把握 頑健性 Surge vs. Baseに合わせたPurchasePlanの組み合わせ最適化 更に高速なboot timeの追求 リトライ時のコスト跳ねを避ける小さなジョブを志向 文化 変更前後のコスト確認を習慣化 システム設計・A/Bテストの設計でコストを変数に 自動化 コスト異常の検知とリカバリの自動化
  37. Copyright © SmartNews, Inc. All rights reserved. • ダッシュボードは灯台。打ち手と推進力の源泉 •

    コスト構造把握のための十分な投資は不可欠 • 正しいコスト構造の理解は正しい打ち手を導く • Instance Typeを適切に選ぶポリシーの実装 • Karpenterを使いスケーリング性能を向上 • On-DemandへのFailoverの実装 Summary 課題 エンジニア教育 • AWSエキスパートと協働で社内セッションを開催 • Spot Instance と Graviton の導入進捗をみるダッシュボードの構築 安定したSpot活用 シームレスな移行 • 移行するサービスの選定基準 • Gravitonのサポート • Spot/On-Demandを組み合わせたK8s/Deployment定義 取り組み タスクフォース • コスト削減に特化したチームとPICを明確に決めることは重要 計測より始めよ 基本に忠実 • Quick Win Optimization/FinOpsを基本的な施策を愚直に進める