V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
scalaer
V2EX  ›  程序员

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

  •  
  •   scalaer · 143 天前 · 2246 次点击
    这是一个创建于 143 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    😭

    xx

    第 1 条附言  ·  143 天前
    Read queries: 226746 Write queries: 144
    13 条回复    2023-12-06 13:55:27 +08:00
    esile
        1
    esile  
       143 天前 via Android
    这是怎么实现的🤣
    scalaer
        2
    scalaer  
    OP
       143 天前
    @esile 这个产品标注了 D1 (Beta), 是不是意味着就是不靠谱 😂
    MossFox
        3
    MossFox  
       143 天前
    真的吗,看看源程序。

    这么大的数字第一时间为什么只会觉得是 Cloudflare 的问题
    NessajCN
        4
    NessajCN  
       143 天前
    是不是用了 useEffect()之类的 hook
    scalaer
        5
    scalaer  
    OP
       143 天前
    @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
        6
    scalaer  
    OP
       143 天前
    @NessajCN 对,这个有影响吗
    NessajCN
        7
    NessajCN  
       143 天前
    @scalaer 影响很大,要是没指定 [] 当依赖,一秒钟给你请求几百次
    oldshensheep
        8
    oldshensheep  
       143 天前
    date 有没有加索引?没有加索引的话会全表扫描。Cloudflare 计算的是扫描到的行数作为请求量的
    metrue
        9
    metrue  
       143 天前
    你这个“30 多个”指的是 RPS, 你说的 "22W 个" 是 Total 吧,所以别让大家用的原因是什么呢?
    scalaer
        10
    scalaer  
    OP
       143 天前
    @NessajCN 上面那个统计是 worker 接收到的统计, 实际请求量应该就是 30 多个左右吧

    @oldshensheep 是的,应该 io 一次就算一个请求了,还没有找到加 index 的位置,先下线吧😭
    scalaer
        11
    scalaer  
    OP
       143 天前
    @metrue 踩了坑提醒大家,22w 个全是 d1 的 read request
    oldshensheep
        12
    oldshensheep  
       143 天前
    加索引不是写个 SQL 就行了嘛
    Rheinmetal
        13
    Rheinmetal  
       142 天前
    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.

    是不是频繁全表扫描的问题?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2821 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:55 · PVG 13:55 · LAX 22:55 · JFK 01:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.