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

Direct VPC egress移行で起こったコスト低減と棚ぼた改善

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for CommuneDevelopers CommuneDevelopers
July 07, 2024
230

Direct VPC egress移行で起こったコスト低減と棚ぼた改善

2024年7月5日(金)に開催された「第23回 酒とゲームとインフラとGCP」にコミューン株式会社SREエンジニアの加藤 智也さんが登壇した際の資料です。ぜひ、ご覧ください。

リンク集
・コミューン株式会社コーポレートサイト:https://communeinc.com/ja
・採用情報:https://communeinc.com/ja/careers
・会社情報 エンジニアVer:https://www.notion.so/commmune/ver0b895a0187ef4954a2d5182afd82082d
・Commune Engineer Blog:https://tech.commune.co.jp/
・Xアカウント(Commune Developers):https://twitter.com/CommuneDev
・Youtube:https://www.youtube.com/channel/UCGBHOcoVzi5t5tWg7GFF-RQ

Avatar for CommuneDevelopers

CommuneDevelopers

July 07, 2024
Tweet

Transcript

  1. 1 © Commune Inc. All rights reserved Direct VPC egress

    移⾏で起こった コスト低減と棚ぼた改善
  2. © Commune Inc. All rights reserved ⾃⼰紹介 2 加藤 智也 ➢

    所属 ◦ コミューン株式会社 開発部 SRE チーム ➢ 経歴 ◦ SIer、社内SE(2年半) ◦ SLOT(3年弱) ◦ HRTech SaaS SRE(2年間) ◦ 2024/02 ⼊社 ➢ 趣味 ◦ 節約、筋トレ、⿇雀、Splatoon3
  3. プロダクト紹介 コミューンは、単なる場作りを越えて活性化し、 事業成果が出るコミュニティサクセスプラットフォーム © Commune Inc. All rights reserved ロイヤルユーザー育成のためのUXを⼀気通貫で提供

    プロジェクトを成功に導く運⽤サポート体制 ⽀援と実績で培ったノウハウ提供 コミューンの3つのポイント 1.プロダクト 2.運⽤サポート 3.ノウハウ提供 3
  4. © Commune Inc. All rights reserved ⽬次 ➢ 移⾏結果 ➢

    Serverless VPC Access connector or Direct VPC egress ➢ コスト ➢ 移⾏⽅法 ◦ Cloud Run ◦ Cloud Functions ◦ Cloud Run Jobs ➢ 棚ぼた改善 ➢ まとめ
  5. © Commune Inc. All rights reserved Serverless VPC Access connector

    Direct VPC egress 6 ‧約-500$/⽉ ‧Cloud Run コンテナ起動時間66% UP 移⾏結果
  6. © Commune Inc. All rights reserved VPC内リソースとプライベートIPで接続する⼿段 7 VPC network

    Cloud SQL Memorystore ComputeEngine Cloud Run Cloud Functions Serverless VPC Access connector Direct VPC egress or VPC外
  7. © Commune Inc. All rights reserved Serverless VPC Access connector

      9 (※参考1:サーバレスVPCアクセスコネクタとの⽐較より引⽤) VMマシン (常時起動&スケールインしない) コストは VMマシン起動時間分のコスト + ネットワークコスト (最低インスタンス数は2)
  8. © Commune Inc. All rights reserved Direct VPC egress 11

    (※参考1:ダイレクトVPC下り(外向き)とはより引⽤) ✖ GA VMマシンは不要!(Cloud RunはVPC内の内部IPを使⽤する) 料⾦は ネットワークコストのみ 2023/8/14 Preview、2024/4/24 GA (※参考2: Cloud Run release notesより抜粋)
  9. © Commune Inc. All rights reserved 12 Serverless VPC Access

    connectorとDirect VPC egressの⽐較 Serverless VPC Access connector Direct VPC egress コスト ⾼ 低 パフォーマンス 低 ⾼ 使⽤するIPアドレスの数 少ない 多い 新旧 旧 新 リリースステージ GA GA (Cloud Run Jobsは除く) (※参考3:ダイレクトVPC下り(外向き)とVPCコネクタの⽐較 ⽐較表より引⽤)
  10. © Commune Inc. All rights reserved コスト 13 ネットワークコスト VMマシン

    ネットワークコスト コスト削減 Direct VPC Egress (上記はコスト削減を分かりやすく⽰す⽬的で使⽤しておりグラフの幅は実際の⽐率を正確に表現していない。) (VMマシンコストはVMインスタンス数×インスタンスタイプに応じた料⾦×時間で計算している。※料⾦単価については参考4のComputeEngine料⾦の汎 ⽤マシンタイプを使⽤している。) 535($/month)
  11. © Commune Inc. All rights reserved 移⾏の流れ 14 コスト試算 コネクタ使⽤

    リソース確認 開発環境 試⽤ Preview General Availability ステージング/本番 部分的 ステージング/本番 全体
  12. © Commune Inc. All rights reserved 15 移⾏⾃体は簡単(Cloud Run) チェックを⼊れる

    VPCとサブネットを選択する (Cloud Run Jobsも同様)
  13. © Commune Inc. All rights reserved 16 注意点① サブネットのCIDR設定 VPCやサブネットを意識せずdefaultサブネットを使いがち

    (asia-northeast1だと、10.146.0.0/20の4096個) (Google Cloudの良いところでもある) ➢ IPアドレスの数 少なくとも Cloud Runインスタンスの4倍の数が必要 (※参考5:VPC ネットワークによるダイレクト VPC 下り(外向き )より引⽤) 最⼤インスタンス数の合計とRevisionの切り 替えを意識してIPアドレスを確保しておく必 要がある (古いRevisionも最⼤20分間IPアドレスを保 持するため) 余裕を持たせるなら8倍の数
  14. © Commune Inc. All rights reserved 18 注意点②-2 使⽤量割り当ての上限緩和申請 最⼤インスタンス数は100まで可能

    (200のリージョンもある) (Communeでは500のCloud Runも存在) ⇨ Cloud Run Admin APIの割り当てを増やす申請 ステージング環境お断りメールが届く 簡単に申請できそう!
  15. © Commune Inc. All rights reserved 19 Cloud Functionsの移⾏① gen1

    → 関数をコピーしてリネーム → オリジナル削除 → 関数コピーでgen2指定 gen1ではDirect VPC egressは使⽤できない
  16. © Commune Inc. All rights reserved 21 Cloud Run Jobsの移⾏①

    Cloud Run Jobs ⽤のコンストラクトを作成(CDK for Terraform ) 1. 可読性 2. 再利⽤性 3. 隠蔽 実装者はこれだけ書けば良い
  17. © Commune Inc. All rights reserved 22 Cloud Run Jobsの移⾏②(改善の余地)

    サービスアカウント、IAMなど もセットで作成 実装者が意識せずとも適切な権限 設定が可能
  18. © Commune Inc. All rights reserved 23 Cloud Run Jobsの移⾏③(やらかし)

    デプロイ⽤スクリプト gcloud beta run jobs deploy ${JOB_NAME} \ --project=${GCLOUD_PROJECT} \ --region=${GCLOUD_REGION} \ --vpc-connector=cloud-run-sql-connector\ --parallelism=0 \ --max-retries=0 \ --task-timeout=$TASK_TIMEOUT \ --wait (参考6: gcloud beta run jobs deploy) オプション消し忘れ ⇨Cloud Runだったら影響範囲でかくてヤバかったかも‧‧‧
  19. © Commune Inc. All rights reserved 棚ぼた(Cloud Runの起動時間が速くなった!?) 25 direct

    VPC egress 切り替え とあるCloud RunのContainer startup latency 66%程度短縮! opentelemetry-sdkなどの影響で 遅くなっていた
  20. © Commune Inc. All rights reserved まとめ 26 ➢ コスト削減効率良い

    ◦ 535($/month)程度削減 (Google Cloudで Cloud Runどっぷりなら) ➢ 影響範囲の確認は丁寧に ◦ リソース変更の際には関連する設定ファイル、スクリプトファ イルは要チェック(今回は運良く助かった) ➢ ⾼速化するかもしれない ◦ 起動時間66%UP
  21. © Commune Inc. All rights reserved 参考資料 27 1. https://cloud.google.com/blog/ja/products/serverless/announcing-direct-

    vpc-egress-for-cloud-run 2. https://cloud.google.com/run/docs/release-notes 3. https://cloud.google.com/run/docs/configuring/connecting-vpc?hl=ja 4. https://cloud.google.com/compute/all-pricing?hl=ja 5. https://cloud.google.com/run/docs/configuring/vpc-direct-vpc?hl=ja 6. https://cloud.google.com/sdk/gcloud/reference/beta/run/jobs/deploy