提供案例
billflare.

硬上限上线前,为失控的 Cloudflare 账单计价:Workers 循环 vs 始终唤醒的 Durable Objects

Lenny Enderle(@lenny_enderle)依据文档为失控场景计价:一个 Worker 以 1,000 req/s 循环一天约 $34,另加 $5 计划费用;而 1,000 个 Durable Objects 整月保持唤醒约 $4,050。在硬上限上线之前,他列出的防护是:每次调用的 CPU 限制、WebSocket 休眠,以及你自己的用量计数器。

适用产品
WorkersDurable Objects
来源
作者经验𝕏 串文
作者
Lenny Enderle(@lenny_enderle)

要点

  • 据该串文,目前已有的是:预算告警——自 7 月起,按量付费账户默认有一条设为 $10 的告警——它只发邮件,不会暂停或封顶用量,并且可能晚到一天,因为用量每天只处理一次。
  • 失控的 Worker(他的假设):1,000 req/s 持续 24 h,每次 7 ms CPU = 8640 万次请求,以及约 6.05 亿 CPU ms;请求 7640 万 × $0.30/百万 = $22.92,CPU 5.75 亿 × $0.02/百万 = $11.50,约 $34,另加 $5 计划。
  • Durable Objects 在唤醒期间按 128 MB 分配计费:1,000 个对象整月唤醒 = 3.24 亿 GB-s,减去包含的 40 万,× $12.50/百万 ≈ $4,050。他说,用旧方式(accept())接受一个 WebSocket 就足以让对象保持唤醒,并引用文档示例:100 个使用非休眠 WebSocket 的对象每月 $419.30,对比启用休眠时为 $20.65(工作负载不同)。
  • 他列出的防护,没有一项是硬上限:每次调用的 CPU 限制(约束每次请求,而不是总量)、WebSocket Hibernation API,以及在你自己的 Durable Object 中统计用量,以便超过限额后拒绝请求。他说他尚未试用已预览的上限。
  • 在回复中,@mptielemans 指出另一项隐蔽费用:run_worker_first: true 会把每个带哈希的 JS/CSS 资源都路由经过 Worker 并计费;Lenny 表示同意,并指出诸如 !/assets/* 的否定模式,@mptielemans 称这需要 Wrangler 4.20+。FlareCost 补充了 Wrangler 配置中的 limits.cpu_ms。

原始来源

  1. 发布

    Lenny Enderle(@lenny_enderle)依据文档为失控场景计价:一个 Worker 以 1,000 req/s 循环一天约 $34,另加 $5 计划费用;而 1,000 个 Durable Objects 整月保持唤醒约 $4,050。在硬上限上线之前,他列出的防护是:每次调用的 CPU 限制、WebSocket 休眠,以及你自己的用量计数器。

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    cloudflare is about to finaly get hard spend caps, starting with workers and durable objects. a preview screenshot went around on oct 26. i can't find them shipped yet. until they do, the only guard is an alert email. so i priced what a runaway bill looks like, straight from the docs. 🧵
  2. 串文:自 7 月起,按量付费账户的预算告警默认设为 $10,仅邮件且属告知性质,并可能在越过阈值一天后才到达。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    what exists today: budget alerts. since july, pay-as-you-go accounts get one by default at $10, and you can set your own threshold. it sends an email. the docs say it's informational only and doesn't pause or cap usage. usage is processed once a day, so the email can arrive a day after you cross the line.
  3. 串文:Worker 以 1,000 req/s 循环 24 h、每次 7 ms CPU,约 $34,另加 $5 计划费用(请求 $22.92,CPU $11.50)。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    runaway workers first. say a loop hits one worker at 1,000 req/s for 24 h, 7 ms cpu each (my assumption): 86.4m requests, ~605m cpu-ms requests: 76.4m x $0.30/m = $22.92 cpu: 575m x $0.02/m = $11.50 about $34 plus the $5 plan. annoying, not a catastrophe.
  4. 串文:1,000 个 Durable Objects 整月唤醒 = 3.24 亿 GB-s,约 $4,050;以旧方式接受一个 WebSocket 就会让对象保持唤醒。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    durable objects are different. duration is billed for the 128 mb an object is allocated, for as long as it's awake and can't hibernate. 1,000 objects awake all month: 324m gb-s, minus 0.4m included, x $12.50/m = ~$4,050. no traffic spike needed. one websocket you accept() the old way is enough to keep an object awake.
  5. 串文:文档示例——100 个对象各有一个 WebSocket 且每秒一条消息,每月 $419.30,对比 10,000 个客户端使用休眠 WebSocket 时的 $20.65——说明你为唤醒时长付费。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    cloudflare's own docs have both cases. 100 objects, one websocket each, a message every second: $419.30 a month. 100 objects with hibernating websockets, 10,000 clients in total, a message a minute each: $20.65. different workloads, so not a controlled test. but you pay for time awake, not for clients.
  6. 串文:目前的防护是每次调用的 CPU 限制、WebSocket 休眠和你自己的用量计数器;价格来自文档,月份按 30 天计。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    what you can do today, none of it a hard cap: - set a per-invocation cpu limit on workers (the docs mention it against "runaway bills" and "denial-of-wallet") - use the websocket hibernation api so idle objects aren't billed for duration - for anything public, count usage in your own durable object and refuse past a limit caveats: the cpu limit bounds each request, not the total. prices from the docs (updated oct 2 and oct 18), 30-day month. i haven't tried the real caps, they're not out.
  7. 串文来源:预算告警文档、账单变更日志(2026 年 7 月 20 日)、Durable Objects 与 Workers 定价,以及 Sid Chatterjee 10 月 26 日的预览。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    sources: budget alerts https://t.co/9dtPEqXM68 billing changelog (20 jul 2026) https://t.co/XYTyHY8i5T durable objects pricing https://t.co/eyqfs5hD1X workers pricing https://t.co/Zt6TIwBJIu preview screenshot: sid chatterjee, oct 26 https://t.co/r4PSIH2q4Z
  8. @mptielemans 的回复:run_worker_first: true 把每个带哈希的 JS/CSS 文件都路由经过 Worker,约占每次页面加载请求的一半,且全部计费。

    到 𝕏 阅读

    Martin

    @mptielemans · 𝕏 原帖

    @lenny_enderle quiet one we hit wasn't a loop: run_worker_first: true routed every hashed js/css file through the worker, ~half of each page load's requests, all billed. does your math assume assets skip the worker?
  9. Lenny:他的计算假设资源会跳过 Worker;加上 run_worker_first 后,它们都会调用 Worker,因此请求数可能变为 2 倍;像 !/assets/* 这样的否定模式可以把它们排除在外。

    到 𝕏 阅读

    Lenny Enderle

    @lenny_enderle · 𝕏 原帖

    @mptielemans good catch, yes my math assumes assets skip the worker. docs say static asset requests are free, but with run_worker_first they all invoke the worker and get billed. so with ~half of every page load being hashed js/css, the request count can be 2x what you'd guess. negative patterns like !/assets/* keep them out of the worker
  10. @mptielemans:他们使用了 ["/*", "!/assets/*"],把 noindex 响应头移到了 _headers 文件,并称否定模式需要 Wrangler 4.20+。

    到 𝕏 阅读

    Martin

    @mptielemans · 𝕏 原帖

    @lenny_enderle same fix we landed on: ["/*", "!/assets/*"]. catch was the worker also set a noindex header on those assets, so that had to move to a _headers file. and negated patterns need wrangler 4.20+, worth a line in the thread
  11. FlareCost(@FlareCost):在 Wrangler 配置中设置 limits.cpu_ms,以限制每次请求的 CPU(Paid 默认为 30 s);超出所含 3000 万 ms 的 CPU 为每百万 $0.02。

    到 𝕏 阅读

    FlareCost

    @FlareCost · 𝕏 原帖

    @lenny_enderle Useful thread. One guard that works today: set limits.cpu_ms in your Wrangler config to cap CPU per request (Paid defaults to 30 s), so a runaway invocation gets stopped early. CPU past the included 30M ms is $0.02 per million: https://t.co/XwoC8hcigH
作者经验Durable Objects +2

烧掉 Durable Objects 额度的反滥用代码:心跳、被拒绝的请求和 D1 扫描

Frank Zeng(@frankzeng2020)说,一段由 AI 编写的反滥用模块把 Durable Objects 推到了 119 万次请求,而每月包含的是 100 万次,额外花了他 $0.15;一封预算告警邮件发现了此事,审计还发现一条 D1 查询路径每天扫描 9.25 亿行,以及每次请求都重新导入签名密钥。他分享了一份只读的自审计提示词。

D1

hiromsaeden:未建索引的 D1 查询循环计费 $2,129.00;一笔 $953.74 善意抵免后仍欠 $645.38。

Cloudflare 社区用户 hiromsaeden 在一篇关于 Workers 和 D1 的个人爱好项目事后分析中称,一条未建索引的 GROUP BY 聚合查询扫描了约 877,000 行以返回 30 行,一次非预期循环在两个计费周期内触发了约 315,000 次运行。仅在 Oct 15 – Nov 15 周期内,就读取了 1,447,580,203,670 行(1.44 万亿行),叠加在上一周期的用量之上。作者称 October 发票 IN-83890481 为 $529.88 USD,已自费全额支付;November 发票 IN-89082487 为 $1,599.12 USD($1,447.58 D1 Rows Read + $6.16 Workers CPU + $145.38 tax);总账单为 $2,129.00 USD,而预期预算约为 $20/month。在 Nov 2–3 发现问题后,作者删除了 Worker 和 D1 数据库;Support 确认所有读取已停止。在案例 #02408621 中,Support 为 October 提供了 $275.00 善意抵免,并建议保留至 Nov 15 开具 November 发票。在案例 #02434399 中,Support 应用了一次性善意抵免 $953.74(其中包含所保留的 $275.00),最终余额为 $645.38 USD,并称审查已完成,无法再做进一步调整。作者已支付 $529.88,称剩余的 $645.38 无力承担,账户将于 Nov 22 降级。作者还称预算警报曾在 $37 时触发一次,但并未阻止扣费,且 D1 目前没有硬性支出上限。公开帖中没有 Cloudflare 员工回复;Support 的处理由作者转述。

社区资源Workers +7

Cloudflare Cost Hub:免费与付费额度对照、成本来源和月底预测

MIT 许可的看板:用 Cloudflare OAuth 登录读取各产品分析数据,把用量按「免费额度内 / 付费包含额度内 / 已计费」着色,列出各实例的成本来源,预测月底费用,并通过邮件发送阈值与预算提醒。