Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Direct VPC egress移行によるコスト低減と棚ぼた改善
Search
Tomoya.K
July 08, 2024
41
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Direct VPC egress移行によるコスト低減と棚ぼた改善
こちらで登壇しました。
https://sake-game.connpass.com/event/312225/
Tomoya.K
July 08, 2024
More Decks by Tomoya.K
See All by Tomoya.K
SREチームの現状とこれから
ktomoya777
0
170
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Cult of Friendly URLs
andyhume
79
7k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Thoughts on Productivity
jonyablonski
76
5.4k
Transcript
1 © Commune Inc. All rights reserved Direct VPC egress
移⾏で起こった コスト低減と棚ぼた改善
© Commune Inc. All rights reserved ⾃⼰紹介 2 加藤 智也 ➢
所属 ◦ コミューン株式会社 開発部 SRE チーム ➢ 経歴 ◦ SIer、社内SE(2年半) ◦ SLOT(3年弱) ◦ HRTech SaaS SRE(2年間) ◦ 2024/02 ⼊社 ➢ 趣味 ◦ 節約、筋トレ、⿇雀、Splatoon3
プロダクト紹介 コミューンは、単なる場作りを越えて活性化し、 事業成果が出るコミュニティサクセスプラットフォーム © Commune Inc. All rights reserved ロイヤルユーザー育成のためのUXを⼀気通貫で提供
プロジェクトを成功に導く運⽤サポート体制 ⽀援と実績で培ったノウハウ提供 コミューンの3つのポイント 1.プロダクト 2.運⽤サポート 3.ノウハウ提供 3
© Commune Inc. All rights reserved Communeのアーキテクチャ 4
© Commune Inc. All rights reserved ⽬次 ➢ 移⾏結果 ➢
Serverless VPC Access connector or Direct VPC egress ➢ コスト ➢ 移⾏⽅法 ◦ Cloud Run ◦ Cloud Functions ◦ Cloud Run Jobs ➢ 棚ぼた改善 ➢ まとめ
© Commune Inc. All rights reserved Serverless VPC Access connector
Direct VPC egress 6 ‧約-500$/⽉ ‧Cloud Run コンテナ起動時間66% UP 移⾏結果
© 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外
© Commune Inc. All rights reserved 8 Serverless VPC Access
connector
© Commune Inc. All rights reserved Serverless VPC Access connector
9 (※参考1:サーバレスVPCアクセスコネクタとの⽐較より引⽤) VMマシン (常時起動&スケールインしない) コストは VMマシン起動時間分のコスト + ネットワークコスト (最低インスタンス数は2)
© Commune Inc. All rights reserved 10 Direct VPC egress
© 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より抜粋)
© 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コネクタの⽐較 ⽐較表より引⽤)
© Commune Inc. All rights reserved コスト 13 ネットワークコスト VMマシン
ネットワークコスト コスト削減 Direct VPC Egress (上記はコスト削減を分かりやすく⽰す⽬的で使⽤しておりグラフの幅は実際の⽐率を正確に表現していない。) (VMマシンコストはVMインスタンス数×インスタンスタイプに応じた料⾦×時間で計算している。※料⾦単価については参考4のComputeEngine料⾦の汎 ⽤マシンタイプを使⽤している。) 535($/month)
© Commune Inc. All rights reserved 移⾏の流れ 14 コスト試算 コネクタ使⽤
リソース確認 開発環境 試⽤ Preview General Availability ステージング/本番 部分的 ステージング/本番 全体
© Commune Inc. All rights reserved 15 移⾏⾃体は簡単(Cloud Run) チェックを⼊れる
VPCとサブネットを選択する (Cloud Run Jobsも同様)
© 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倍の数
© Commune Inc. All rights reserved 17 注意点②-1 最⼤インスタンス数 最⼤インスタンスを100以下にする必要がある
© Commune Inc. All rights reserved 18 注意点②-2 使⽤量割り当ての上限緩和申請 最⼤インスタンス数は100まで可能
(200のリージョンもある) (Communeでは500のCloud Runも存在) ⇨ Cloud Run Admin APIの割り当てを増やす申請 ステージング環境お断りメールが届く 簡単に申請できそう!
© Commune Inc. All rights reserved 19 Cloud Functionsの移⾏① gen1
→ 関数をコピーしてリネーム → オリジナル削除 → 関数コピーでgen2指定 gen1ではDirect VPC egressは使⽤できない
© Commune Inc. All rights reserved 20 Cloud Functionsの移⾏② gen2へ変更してdeploy
→ Cloud Runの画⾯に表⽰
© Commune Inc. All rights reserved 21 Cloud Run Jobsの移⾏①
Cloud Run Jobs ⽤のコンストラクトを作成(CDK for Terraform ) 1. 可読性 2. 再利⽤性 3. 隠蔽 実装者はこれだけ書けば良い
© Commune Inc. All rights reserved 22 Cloud Run Jobsの移⾏②(改善の余地)
サービスアカウント、IAMなど もセットで作成 実装者が意識せずとも適切な権限 設定が可能
© 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だったら影響範囲でかくてヤバかったかも‧‧‧
© Commune Inc. All rights reserved 24 connectorの削除 コネクタの削除はDELETEワンポチですが消さなきゃ節約できません ※簡単に削除可能である⼀⽅で使⽤中のリソースがあっても削除できて
しまう
© Commune Inc. All rights reserved 棚ぼた(Cloud Runの起動時間が速くなった!?) 25 direct
VPC egress 切り替え とあるCloud RunのContainer startup latency 66%程度短縮! opentelemetry-sdkなどの影響で 遅くなっていた
© Commune Inc. All rights reserved まとめ 26 ➢ コスト削減効率良い
◦ 535($/month)程度削減 (Google Cloudで Cloud Runどっぷりなら) ➢ 影響範囲の確認は丁寧に ◦ リソース変更の際には関連する設定ファイル、スクリプトファ イルは要チェック(今回は運良く助かった) ➢ ⾼速化するかもしれない ◦ 起動時間66%UP
© 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
コミューンの会社情報 エンジニア向け会社情報 Xアカウント (Commune Developers) https://commmune.notio n.site/ver-0b895a0187ef4 954a2d5182afd82082d 28
© Commune Inc. All rights reserved