如何优化Firebase功能的响应速度 [英] how to optimize firebase function's response speed

查看:113
本文介绍了如何优化Firebase功能的响应速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基于nodejs 6和firestore的firebase函数,我这样的简单函数总是很慢.我还发现当我在函数中使用set/add firestore时,它总是很慢5-10秒 这是index.js,应用程序从此queryUserDoc api获取响应.

I use firebase function base on nodejs 6 and firestore,my simple function like this is always slow.I also found when i use set/add firestore in function,it always slow maybe 5-10 second this is index.js,app get response from this queryUserDoc api.

`

const accountModel = require('./account');
exports.queryUserDoc = functions.https.onCall((data, context) => {
    const uid = context.auth.token.uid;
    return accountModel.getUserDocByUid(uid)
        .then(doc => {
            return JSON.stringify(({'errCode': ERROR_SUCCESS, 'data': doc.data()}));
        })
        .catch(err => {
            return JSON.stringify(({'errCode': err}));
        });
});

` account.js如下:

` account.js is below:

function getUserDocByUid(uid) {
    return db.collection(DB_COLLECTION_USER).doc(uid).get();
}

当我的应用程序调用此api时,我发现它的速度非常慢.

when my app call this api,i found it so slowly.console is below

推荐答案

为我工作并大大提高了Firebase函数速度的是更新我的函数的位置.我位于欧洲,因此默认设置最初设置为us-central1.更新为europe-west1后,速度从〜5秒变为〜600ms.如此处 https://firebase.google.com/docs/所述,更改区域相对容易.功能/位置 我只是按照他们的榜样就可以走了

What has worked for me and increased significantly the speed of firebase functions, was to update the location of my functions. I'm located in Europe so the default was initially set to us-central1 . After updating to europe-west1 speed went from ~5 seconds to ~600ms. It's relatively easy to change the region as described here https://firebase.google.com/docs/functions/locations I've just followed their example and i was ready to go

这篇关于如何优化Firebase功能的响应速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆