【发布时间】:2019-09-13 01:35:39
【问题描述】:
我想知道,即使是非常简单的代码,为什么 Firestore 比使用 Firebase 的实时数据库慢得多。
Cloud Firestore:
冷启动:函数执行耗时 1562 毫秒
热启动:函数执行耗时 132 毫秒
exports.firestore = functions.https.onRequest((req, res) => {
var teamRef = instance.collection('teams').doc("TGQ");
teamRef.get().then(doc => {
res.status(200).send(doc.data()).end();
return;
}).catch(error => {
res.status(200).send("Document cant be found").end();
});
});
实时数据库
冷启动:函数执行耗时 815 毫秒
热启动:函数执行耗时 13 毫秒
exports.realtimedb = functions.https.onRequest((req, res) => {
var realtime = admin.database();
realtime.ref('/teams/' + "TGQ").once('value').then((snapshot) => {
var document = snapshot.val();
res.status(200).send(document).end();
return;
}).catch(error => {
res.status(200).send("Document cant be found").end();
});
});
为什么 Cloud Firestore 对简单的功能执行如此缓慢?我个人认为,对于我正在运行的项目,Firestore 是适合我的,但它在冷启动时慢了一倍,在热启动时慢了 10 倍,这似乎非常令人不快。
两台服务器也都托管在 US Central 1 上。我研究了运行它们的 js 文件的复杂性,这两个示例是从同一个文件中运行的,以给出一个均匀的结果。
【问题讨论】:
-
Firestore 示例的代码导出
realtimedb,Realtime 反之亦然。这是一个错字,还是意味着你的结果被翻转了? -
已更新,这是一个复制和粘贴错误 - 感谢您的现场!
标签: node.js firebase firebase-realtime-database google-cloud-firestore google-cloud-functions