Firebase功能会延迟冷启动时间 [英] Firebase functions slow cold start time

查看:101
本文介绍了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.

冷启动: Function execution took 16172 ms, finished with status code: 200 之后:Function execution took 1002 ms, finished with status code: 304

这是预期的行为吗,可能是什么原因引起的?

Is this expected behaviour and what could be causing it?

推荐答案

更新:对于我来说,冷启动时间似乎不再是节点8的问题.对于那些对通过App Engine进行cron任务来保持其功能正常运行感到好奇的个人,我将在下面留下我的答案.但是,还有一种新的cron方法可用,可以使它们更容易保暖. 请参阅Firebase博客以获取有关cron和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.

我的解决方案是向所有API添加"ping"功能,并创建一个类似于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.

请参阅此教程以了解App引擎的日程安排: 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天全站免登陆