如何保持Google Cloud Functions的温暖? [英] How can I keep Google Cloud Functions warm?

查看:126
本文介绍了如何保持Google Cloud Functions的温暖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这首先错过了使用Cloud Functions的意义,但是在我的特定情况下,我正在使用Cloud Functions,因为这是将Next.js与Firebase Hosting桥接的唯一方法.我不需要使其具有成本效益,等等.

I know this misses the point of using Cloud Functions in the first place, but in my specific case, I'm using Cloud Functions because it's the only way I can bridge Next.js with Firebase Hosting. I don't need to make it cost-efficient, etc.

话虽如此,Cloud Functions的冷启动时间简直无法忍受,还不能投入生产,对于我的样板,平均大约需要10到15秒.

With that said, the cold boot times for Cloud Functions are simply unbearable and not production-ready, averaging around 10 to 15 SECONDS for my boilerplate.

我当然看过Google的这部影片( https://www.youtube.com /watch?v = IOXrwFqR6kY ),它讨论了如何减少冷启动时间.简而言之:1)Trim依赖项,2)Trial&依赖项版本在Google网络上缓存的错误,3)延迟加载.

I've certainly watched this video by Google (https://www.youtube.com/watch?v=IOXrwFqR6kY) that talks about how to reduce cold boot time. In a nutshell: 1) Trim dependencies, 2) Trial & error for dependencies' versions for cache on Google's network, 3) Lazy loading.

但是,嘿,1)我可以裁剪的依赖项太多了. 2)我怎么知道哪个版本被更多缓存? 3)只有太多依赖项可以延迟加载.

But hey, 1) there are only so many dependencies I can trim. 2) How would I know which version is more cached? 3) There are only so many dependencies I can lazy load.

另一种方法是避免全部冷启动.从本质上讲,我可以使(一个或唯一一个)云功能保持温暖是什么好方法?

Another way is to avoid the cold boot all together. What's a good way or hack that I can essentially keep my (one and only) cloud function warm?

推荐答案

对于所有无服务器"计算提供程序,总会有某种形式的冷启动成本无法消除.即使您能够通过ping通使单个实例保持活动状态,系统也可以启动任意数量的其他实例来处理当前负载.这些新实例将产生冷启动成本.然后,当负载减少时,不必要的实例将被关闭.

With all "serverless" compute providers, there is always going to be some form of cold start cost that you can't eliminate. Even if you are able to keep a single instance alive by pinging it, the system may spin up any number of other instances to handle current load. Those new instances will have a cold start cost. Then, when load decreases, the unnecessary instances will be shut down.

正如您所发现的,有很多方法可以使您的冷启动成本降至最低,但是无法消除这些成本.

There are ways to minimize your cold start costs, as you have discovered, but the costs can't be eliminated.

如果您绝对要求热服务器处理24/7的请求,则需要管理自己的运行24/7的服务器(并支付运行24/7的服务器的费用).如您所见,无服务器的好处是您无需管理或扩展自己的服务器,而只为使用的服务器付费,但是与项目相关的冷启动成本却不可预测.那是个权衡.

If you absolutely demand hot servers to handle requests 24/7, then you need to manage your own servers that run 24/7 (and pay the cost of those servers running 24/7). As you can see, the benefit of serverless is that you don't manage or scale your own servers, and you only pay for what you use, but you have unpredictable cold start costs associated with your project. That's the tradeoff.

这篇关于如何保持Google Cloud Functions的温暖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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