Firebase Cloud Functions execution time is so fluctuate

六眼飞鱼酱① 提交于 2021-02-11 08:07:29

问题


I got this from google cloud console. I don't understand why after the function is executed, it should turn hot for some duration. However, after deploying the function and call it, I found cold start and then drop to actual and then increase to cold start again. Please help!

// 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 version

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

回答1:


There is potential for a lot of variance in you function. It's doing all of the following tasks, none of which have guarantees how long they will take:

  1. Using Firebase Auth to effectively sign in a user
  2. Fetching an ID token for that user
  3. Sending a response to the client, wherever in the world they are, with whatever connection speed.

If you want to understand the performance characteristics of your function, you should profile each one of these steps. The sending of the response may not be possible to benchmark, and could be highly variable based on their physical location and connection speed.

If you have solid benchmarks that suggest that Cloud Functions is underperforming compared to expectations, please send those to Firebase support. https://firebase.google.com/support/



来源:https://stackoverflow.com/questions/51759752/firebase-cloud-functions-execution-time-is-so-fluctuate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!