云函数设置限制最大实例

Cloud function set limit max instances

我目前正在尝试找出一种方法来限制云功能请求,以保护自己免受巨额账单的侵害。如果我将 Max instances 设置为 0,我的函数仍然会接受请求吗?如果是,那么我可以在 firestore 达到预期限制时在 firestore 中添加一个计数器增量云函数将 Max instances 设置为 0 是否会让我免于意外账单

是否有任何其他服务有限制选项我不想随用随付

What if I set Max instances to 0 will my function still take request?

我怀疑你是否真的可以一开始就将它设置为 0。如果您将鼠标悬停在自动缩放输入字段的信息 (❔) 图标上,它会显示 “留空或设置为 0 以清除此控件并根据需要自动创建新实例。” 这实际上意味着输入 0 将删除最大限制。

can I add a counter increment in firestore when it reaches expected limit cloud function

您可以通过在每次调用后增加数据库中的计数来跟踪调用总数,并尝试使用 Cloud Functions REST API to updatemaxInstances 到一个更小的数字(不是 0 因为解释的原因以上)根据需要。

来自documentation,

When you specify a max instances limit, you are specifying an upper limit. Setting a large limit does not mean that your function will scale up to the specified number of instances. It only means that the number of instances that co-exist at any point in time should not exceed the limit

In some cases, such as rapid traffic surges, Cloud Functions may, for a short period of time, create more instances than the specified max instances limit. If your function cannot tolerate this temporary behavior, you may want to factor in a safety margin and set a lower max instances value than your function can tolerate.