Cloud Cost Sense
Google Cloud Tasks の費用:Operation、Retry、Worker
API operation、delivery attempt、payload size、retry、network transfer、worker usage から Google Cloud Tasks の費用を見積もります。
作成した task 数ではなく billable operation を数える
Cloud Tasks は API call と push delivery attempt を operation として課金します。毎月最初の 100 万 operation は無料で、次の tier から 100 万 operation 単位の料金が適用されます。1 task には通常、create call と成功した delivery という少なくとも 2 operation が発生するため、task 数だけでは usage を過小評価します。List call や他の API action も operation を増やします。
Payload は 32 KB chunk 単位で計測されます。そのため 96 KB の task は作成時に 3 operation、1 回の delivery attempt でさらに 3 operation と数えられます。月間 API action と delivery attempt にそれぞれ payload chunk 数を掛け、現在の無料枠を差し引き、公式 Cloud Tasks pricing page で最新 tier 料金を確認してください。
Retry と downstream processing を別に予算化する
Timeout や worker の失敗 response による retry を含め、すべての push delivery attempt が課金対象です。常に 1 回で届くと仮定せず、予想 task 数 × 平均 attempt 数でモデル化します。最大 attempt 数と retry duration を制限し、exponential backoff を使い、再 delivery が database write、message、有料 external API call を重複させないよう handler を idempotent にします。
Cloud Tasks の料金には task を処理する service は含まれません。各 attempt が使う Cloud Run、Functions、App Engine、database、logging、external API の費用を加えます。HTTP target には通常の network charge も適用されるため、構成上可能なら queue と worker を近づけ、実際の network path を見積もってください。
Dispatch rate で worker の予算を守る
Queue rate limit は初回 attempt と retry の両方に適用されます。Worker が安全に処理できる capacity に合わせて maximum dispatches per second と maximum concurrent dispatches を設定します。Burst を平準化すると、追加 attempt、latency、downstream compute や database cost を増やす 429 または 503 response を減らせます。
Task attempt count、response code、queue depth、worker duration を一緒に監視します。Queue 自体が安くても、高価または overload した target を露出させる場合があります。通常 traffic、failure spike、scheduled burst をそれぞれ試算し、Cloud Tasks operation と処理全体の費用を予算に含めてください。