2025年12月27日土曜日

cloudflare durable objectを使う

アトミックな処理をする。
例えばルーム内のゲーム情報の管理など。
ただしworkerは長時間稼働ができないので、ユーザーがDOにalermを送る形式となる。





📌 Durable Objects の料金概要

🚀 プラン

  • Free(無料)プラン

    • SQLite ストレージバックエンドのみ利用可能

    • 制限を超えると該当リソースの処理が失敗する(課金なし)Cloudflare Docs

  • Paid(有料)プラン

    • SQLite または Key-Value(KV)ストレージバックエンド を選択可能

    • Workers Paid プラン(月額 $5 のベース費用)が前提になる場合が多い(※参考実装例)Cloudflare Docs


🧮 課金対象と料金

1) Compute(実行時間・リクエスト)

項目無料枠有料料金
リクエスト数100,000 / 日1,000,000 / 月 included
追加リクエスト$0.15 / 1M リクエスト
Duration(Durable Object 活動時間)13,000 GB-s / 日400,000 GB-s / 月 included
追加 Duration$12.50 / 1M GB-s

(GB-s = 持続時間 × メモリ量 / 1GB)Cloudflare Docs


2) Storage(永続ストレージ)

📌 SQLite バックエンド(推奨)

項目無料枠有料料金
読み込み5M / 日25B/月 included
書き込み100k / 日50M/月 included
ストレージ容量5 GB total5 GB-month included
追加$0.001 / 1M rows read
$1.00 / 1M rows write
$0.20 / GB-month

※SQLite Storage の課金は 2026 年 1 月以降適用予定と公式にアナウンスあり。Cloudflare Docs

📌 Key-Value バックエンド(Paid プランのみ)

項目無料枠有料料金
Read 単位1Mincluded
Write 単位1Mincluded
Delete 単位1Mincluded
Stored Data1 GBincluded
追加$0.20 / 1M read units
$1.00 / 1M write units
$0.20 / GB-month

(Key-Value は読み書きサイズ単位で課金)Cloudflare Docs


📊 例:ざっくり月額コスト

  • 低トラフィック用途

    • リクエスト 1.2M、Duration 50,000GB-s 程度 → おそらく 数ドル〜$10 程度 / 月
      (無料枠内でほぼ収まる場合)TheServerless.Dev

  • WebSocket / リアルタイム用途

    • 多数接続 & 長時間活動 → Duration 増 → 数十〜数百ドルに到達可能
      (例: 100 DO × 50WS × 活動 → $130 程度)Cloudflare Docs



0 件のコメント:

コメントを投稿

あいうえお