首页 > 解决方案 > Is there a way to detect cold start in Google Cloud Functions?

问题描述

When my GCF function is in a cold start state, I need to send a "wait" signal to the invoking endpoint to let it know that response time may be a bit slower. (For context, this is the back-end of a Slack slash function, which requires an initial response within three seconds. We're seeing > 3s gcf spin-up time at cold start though).

If relevant, the relevant cloud function is also performing calls to firestore.

Is there a way to detect when a cloud function is spinning up from cold start? Can't find any mention of this anywhere... Thank you.

标签: google-cloud-platformgoogle-cloud-functions

解决方案


您可以将 Cloud Functions 迁移到 App Engine 以便有预热请求并避免冷启动。

正如@John Hanley 提到的那样,减少冷启动时间的唯一方法是优化您部署的功能。

谷歌建议:

  • 始终删除临时文件
  • 明智地使用依赖项
  • 使用全局变量在未来的调用中重用对象
  • 对全局变量进行延迟初始化

查看此链接和此视频以了解可能函数的最佳实践


推荐阅读