30 多个请求导致了 22w 个查询 request,😭现在千万别用 cloudflare serverless database(D1)

154 天前
 scalaer

刚发的帖子 https://v2ex.com/t/997992 , 上线不到一会儿, 账户请求限额就超了

😭

2273 次点击
所在节点    程序员
13 条回复
esile
154 天前
这是怎么实现的🤣
scalaer
154 天前
@esile 这个产品标注了 D1 (Beta), 是不是意味着就是不靠谱 😂
MossFox
154 天前
真的吗,看看源程序。

这么大的数字第一时间为什么只会觉得是 Cloudflare 的问题
NessajCN
154 天前
是不是用了 useEffect()之类的 hook
scalaer
154 天前
@MossFox 它可能是 io 一次就算一次请求了

```
async function handleGetTrendsRequest(request, env) {
try {

const data = await env.DATABASE.prepare("SELECT * FROM google_trend WHERE date = ?")
.bind(date)
.all();

return createCORSResponse(JSON.stringify(data));
} catch (error) {
return new Response(error.message, { status: 500 });
}
}
```
scalaer
154 天前
@NessajCN 对,这个有影响吗
NessajCN
154 天前
@scalaer 影响很大,要是没指定 [] 当依赖,一秒钟给你请求几百次
oldshensheep
154 天前
date 有没有加索引?没有加索引的话会全表扫描。Cloudflare 计算的是扫描到的行数作为请求量的
metrue
154 天前
你这个“30 多个”指的是 RPS, 你说的 "22W 个" 是 Total 吧,所以别让大家用的原因是什么呢?
scalaer
154 天前
@NessajCN 上面那个统计是 worker 接收到的统计, 实际请求量应该就是 30 多个左右吧

@oldshensheep 是的,应该 io 一次就算一个请求了,还没有找到加 index 的位置,先下线吧😭
scalaer
154 天前
@metrue 踩了坑提醒大家,22w 个全是 d1 的 read request
oldshensheep
154 天前
加索引不是写个 SQL 就行了嘛
Rheinmetal
154 天前
Rows read measure how many rows a query reads (scans), regardless of the size of each row. For example, if you have a table with 5000 rows and run a SELECT * FROM table as a full table scan, this would count as 5,000 rows read. A query that filters on an unindexed column may return fewer rows to your Worker, but is still required to read (scan) more rows to determine which subset to return.

是不是频繁全表扫描的问题?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/998046

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX