[英]How fast is counting documents in Cloud Firestore?
我在测试数据库中创建了一些包含许多文档的 collections,然后针对它运行 COUNT() 查询。
通过Node.js Admin SDK生成最小文件的代码:
const db = getFirestore();
const col = db.collection("10m");
let count = 0;
const writer = db.bulkWriter();
while (count++ < 10_000_000) {
if (count % 1000 === 0) await writer.flush();
writer.create(col.doc(), {
index: count,
createdAt: FieldValue.serverTimestamp()
})
}
await writer.close();
然后我用:
for (const name of ["1k", "10k", "1m", "10m"]) {
const start = Date.now();
const result = await getCountFromServer(collection(db, name));
console.log(`Collection '${name}' contains ${result.data().count} docs (counting took ${Date.now()-start}ms)`);
}
我得到的结果是:
数数 | 多发性硬化症 |
---|---|
1,000 | 120 |
10,000 | 236 |
100,000 | 401 |
1,000,000 | 1,814 |
10,000,000 | 16,565 |
我运行了一些带有限制和条件的额外测试,结果始终符合上述统计结果的数量。 因此,例如,计算 1000 万文档的集合的 10% 大约需要 1.5 到 2 秒。
因此,基于此,在达到 60 秒超时之前,您最多可以计算 40m 左右的文档。 老实说,考虑到每计算 1,000 份文档,您需要支付 1 份文档读取费用,您可能希望在此之前切换到存储 计数器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.