Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase云函数执行时间如此波动_Firebase_Google Cloud Functions - Fatal编程技术网

Firebase云函数执行时间如此波动

Firebase云函数执行时间如此波动,firebase,google-cloud-functions,Firebase,Google Cloud Functions,我从谷歌云控制台得到了这个。我不明白为什么在函数执行后,它会在一段时间内变热。然而,在部署函数并调用它之后,我发现冷启动,然后下降到实际值,然后再次增加到冷启动。请帮忙 // index.js import * as functions from 'firebase-functions' import express from 'express' import cors from 'cors' import auth from 'controllers/auth' const authApp

我从谷歌云控制台得到了这个。我不明白为什么在函数执行后,它会在一段时间内变热。然而,在部署函数并调用它之后,我发现冷启动,然后下降到实际值,然后再次增加到冷启动。请帮忙

// index.js
import * as functions from 'firebase-functions'
import express from 'express'
import cors from 'cors'

import auth from 'controllers/auth'

const authApp = express()
authApp.use(cors({ origin: true }))
authApp.use(auth)
authApp.use('*', unknownPathHandler, errorMiddleware)
const authApi = functions.https.onRequest(authApp)

exports.auth = authApi


// controllers/auth.js
app.post('/user', verifySecretKey, (req, res, next) => {
  const { email, password } = req.body
  return appFirebase.auth().signInWithEmailAndPassword(email, password)
    .then(() => {
      return appFirebase.auth().currentUser.getIdToken().then((token) => {
        return res.end(token)
      })
    })
    .catch((err) => next(err))
})
firebase版本

"firebase-admin": "5.12.0",
"firebase-functions": "1.0.2",

你的函数可能会有很多变化。它正在执行以下所有任务,但没有一项任务可以保证需要多长时间:

  • 使用Firebase Auth有效登录用户
  • 正在获取该用户的ID令牌
  • 以任何连接速度向客户机发送响应,无论客户机在世界的任何地方
  • 如果您想了解函数的性能特征,您应该分析这些步骤中的每一个。响应的发送可能无法进行基准测试,并且可能会根据其物理位置和连接速度发生很大变化


    如果您有可靠的基准表明云功能的性能低于预期,请将其发送给Firebase支持部门

    在不显示代码的情况下,堆栈溢出对您没有多大帮助。@DougStevenson感谢您的回答,我提供了一个api。这有帮助吗?非常感谢,但我有另一个api在firestore中使用简单查询。但是,行为是相同的(如上图所示,波动执行时间)。我不知道这是否与我使用的firebase函数版本有关?。此外,我怀疑在过去的几天里,API的速度明显比平时慢。