提供案例
billflare.

在 D1 上自托管分析:决定账单的是被扫描的行,而不是被返回的行

Lynn(@hizachlynn)估算了一个没有预聚合 rollup 表、以 D1 为后端的分析工具会如何随规模变化:仪表板查询会扫描原始事件,因此在每月 100 万次 pageview 时,一次加载约扫描 4.28 亿行;所有数字都是作者的估算。

适用产品
D1
来源
作者经验𝕏 帖子
作者
Lynn(@hizachlynn)

要点

  • 他表示,D1 按被扫描的行计费,而不是按被返回的行,因此在没有预聚合 rollup 表时,每一次仪表板查看都会对原始事件历史执行 count(distinct) 和 group by。
  • 他的 30 天估算:每月 1 万次 pageview ≈ 每次加载扫描 18 万行;10 万次 ≈ 500 万行,一次刷新就会用完全部每日免费读取额度;100 万次 ≈ 4.28 亿行,在他的本地测试中重度 join 耗时超过 70 s,超出 D1 的 30 s 查询超时。
  • 在付费计划上,他把 4.28 亿行估为每次加载约 $0.43,因此一个小团队每天打开统计 20 次,每月仅读取就约需 $230(估算)。他表示,由于会话心跳和索引,一次 pageview 会触发约 9 次行写入。
  • 他补充说,D1 对每个数据库按顺序执行查询,因此一条慢的仪表板查询可能会阻塞事件写入。2026-10-28 阅读的 D1 定价页面确认,rows read 统计的是被扫描的行,并且 Free 每天包含 500 万行读取。

原始来源

  1. 发布

    Lynn(@hizachlynn)估算了一个没有预聚合 rollup 表、以 D1 为后端的分析工具会如何随规模变化:仪表板查询会扫描原始事件,因此在每月 100 万次 pageview 时,一次加载约扫描 4.28 亿行;所有数字都是作者的估算。

    Lynn

    @hizachlynn · 𝕏 原帖

    $29 lifetime for analytics sounds like a great deal until you calculate the actual d1 database bill. d1 bills by rows scanned, not returned. without pre-aggregated rollup tables, every dashboard view runs count(distinct) and group by directly over raw event history. do the basic math for a 30-day window: >> 10k pv/mo: ~180k rows scanned per load. fine. >>> 100k pv/mo: ~5m rows scanned. a single refresh burns your entire daily free read limit. after that, queries break and tracking drops. >>>> 1m pv/mo: ~428m rows scanned. heavy joins take 70s+ in local tests, way past d1's hard 30s query timeout. on the paid plan, 428m rows is ~$0.43 per load. a small team opening stats 20 times a day is looking at ~$230/mo just in read costs. and writes aren't cheap either. between session heartbeats and indexes, 1 pageview triggers ~9 row writes. at 1m pv/mo, you burn through the free daily write limit immediately. the real dealbreaker? d1 executes queries sequentially per db. one slow 30-second dashboard query will literally block incoming event ingestion and silently drop tracking data. $29 once looks cheap next to a monthly subscription, until one bad month on d1 hands you a cloudflare bill that wipes out years of savings.
社区资源Workers +5

Polaris:在 Workers 上自托管的 Free 计划剩余额度与成本仪表盘

etak64n/polaris 是一个基于 Cloudflare Workers 的 MIT 许可仪表盘,显示每项 Free 计划限额还剩多少,以及 Workers、D1、R2、KV、Durable Objects、Queues、Workflows、Hyperdrive、Browser Run 和 Workers AI 的成本/指标。它部署在 Cloudflare Access 之后,并用作为密钥保存的 API token 读取 Analytics。

其他产品

mateuspainhob17:因一项已不再使用的功能被收取 $4.88,且为第二个月,并已提交工单。

Cloudflare 社区用户 mateuspainhob17(toasty.pet)称收到一封 $4.88 费用的失败发票邮件。作者称上个月也出现了同样的费用,随后该功能已被停用,但即使该功能未被使用,$4.88 费用再次出现。帖文未点明该功能名称。社区 MVP sjr 询问是哪项功能,并指引作者查看账单工单指南。作者后来称已创建工单并询问下一步该怎么做;sjr 称等待工单回复。公开帖中没有 Cloudflare 员工回复,也未报告工单结果。

社区资源Workers +8

Cloudflare Medivh:自部署的近实时账单估算与告警

一个可自部署的开源监控:在 Cloudflare 按日更新的计费用量之上叠加当日估算费用,定期推送汇总,当前账期超过预算时调用 Webhook。