[英]Rate limit / throttle google cloud function that subscribes to a PubSub topic
So I have a cloud function that subscribes to a Pub/Sub topic, and the function interacts with a 3rd party service API that has a hard rate limit. 因此,我有一个订阅了发布/订阅主题的云函数,并且该函数与具有硬速率限制的第三方服务API交互。 This creates a problem, when the PubSub topic suddenly gets a surge of incoming traffic, the cloud function will be invoked frequently enough to go over the 3rd party API rate limit.
这就产生了一个问题,当PubSub主题突然收到大量传入流量时,云函数将被频繁调用,以超过第三方API速率限制。
What's the best way to solve this problem? 解决此问题的最佳方法是什么? Am I able to throttle the PubSub topic or I have to implement some backoff logic in the cloud function?
我是否可以限制PubSub主题,或者必须在云函数中实现一些退避逻辑? Thanks!
谢谢!
You can control the scaling behavior of Cloud Functions to some degree. 您可以在某种程度上控制Cloud Functions的扩展行为 。 From the linked documentation:
从链接的文档中:
You can set max instances for an individual function during deployment.
您可以在部署期间为单个功能设置最大实例数。 Each function can have its own max instances limit.
每个函数可以有自己的最大实例数限制。 Functions scale independently of each other.
功能彼此独立缩放。
To set a max instances limit using the gcloud command-line tool, use the --max-instances flag at deploy time:
要使用gcloud命令行工具设置最大实例数限制,请在部署时使用--max-instances标志:
gcloud beta functions deploy FUNCTION_NAME --max-instances 10 FLAGS...
You will have to figure out how many concurrent instances are within the limits of this other API. 您将必须确定在此其他API的限制内有多少个并发实例。 If one instance is still able to generate too many requests, you will have to implement your own backoff, as you are not able to set the rate of execution, just the max number of allocated instances.
如果一个实例仍然能够生成太多请求,则您将必须执行自己的退避,因为您无法设置执行速率,而只能设置已分配实例的最大数量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.