Firebase 运行缓慢的冷启动时间 [英] Firebase functions slow cold start time

查看:47
本文介绍了Firebase 运行缓慢的冷启动时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了此处端点启动应该是透明,我认为这意味着冷启动时间不应与常规执行时间不同.现在还是这样吗?我们在所有端点上的冷启动时间都非常缓慢且无法使用 - 大约 16 秒.

I read here endpoint spin-up is supposed to be transparent, which I assume means cold start times should not differ from regular execution times. Is this still the case? We are getting extremely slow and unusable cold start times - around 16 seconds - across all endpoints.

冷启动:函数执行耗时 16172 ms,完成状态码:200之后:函数执行耗时 1002 ms,完成状态码:304

这是预期的行为吗?是什么原因造成的?

Is this expected behaviour and what could be causing it?

推荐答案

更新: 冷启动时间似乎不再是节点 8 的问题,至少对我而言.对于任何想通过 App Engine 使用 cron 任务保持其功能温暖的人,我将在下面留下我的答案.但是,还有一种新的 cron 方法可用,可以更轻松地使它们保持温暖.有关 cron 和 Firebase 的更多详细信息,请参阅 firebase 博客.

UPDATE: The cold start times seem to no longer be an issue with node 8, at least for me. I'll leave my answer below for any individuals curious about keeping their functions warm with a cron task via App Engine. However, there is also a new cron method available that may keep them warm more easily. See the firebase blog for more details about cron and Firebase.

我的冷启动时间很荒谬,以至于浏览器在等待请求时会超时.(就像它正在等待 Firestore API 完成一样).

My cold start times have been ridiculous, to the point where the browser will timeout waiting for a request. (like if it's waiting for a Firestore API to complete).

示例一个创建新用户帐户的函数(auth.user().onCreate 触发器),然后在 Firestore 中设置用户配置文件.

Example A function that creates a new user account (auth.user().onCreate trigger), then sets up a user profile in firestore.

  • 部署后首次启动:始终在 30 到 60 秒之间,在冷的第一次尝试时经常给我一个连接错误"(这是在等待几秒钟后 Firebase CLI 说部署完成"!"
  • 冷启动:10 - 20 秒
  • 温暖时:所有这些都在大约 400 毫秒内完成.
  • First Start After Deploy: consistently between 30 and 60 seconds, frequently gives me a "connection error" on the first try when cold (this is after waiting several seconds once Firebase CLI says "Deploy Complete!"
  • Cold Start: 10 - 20 seconds
  • When Warm: All of this completes in approximately 400ms.

正如您想象的那样,没有多少用户会等待超过几秒钟来设置帐户.我也不能让它在后台发生,因为它是应用程序进程的一部分,需要配置文件设置来存储输入数据.

As you can imagine, not many users will sit around waiting more than a few seconds for an account to be setup. I can't just let this happen in the background either, because it's part of an application process that needs a profile setup to store input data.

我的解决方案是将ping"函数添加到我的所有 API 中,并创建一个类似 cron 的调度程序任务,使用应用引擎每分钟 ping 我的每个函数.

My solution was to add "ping" function to all of my API's, and create a cron-like scheduler task to ping each of my functions every minute, using app engine.

确保 ping 函数执行某些操作,例如访问 firestore 文档或设置新用户帐户,而不仅仅是响应 http 请求.

Ensure the ping function does something, like access a firestore document, or setup a new user account, and not just respond to the http request.

请参阅本教程以了解应用引擎调度:https://cloud.google.com/appengine/docs/flexible/nodejs/scheduling-jobs-with-cron-yaml

See this tutorial for app engine scheduling: https://cloud.google.com/appengine/docs/flexible/nodejs/scheduling-jobs-with-cron-yaml

这篇关于Firebase 运行缓慢的冷启动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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