简体   繁体   English

订阅PubSub主题的速率限制/限制Google云端功能

[英]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.

相关问题 带有 pubsub 触发主题的云 Function 不起作用 - Cloud Function with pubsub trigger topic is not working 在谷歌云中使用 PubSub function - Consume PubSub in Google cloud function 通过 mosquitto 代理发布到谷歌云中不同的 pubsub 主题? - Publish to different pubsub topic in Google cloud via mosquitto broker? 在Compute Engine中使用Google Cloud Pubsub发布到主题 - Publish to a topic using Google Cloud Pubsub within Compute Engine 在PubSub主题上使用Cloud Run - Using Cloud Run on a PubSub topic 谷歌云 Function 错误 - 发布订阅到 BigQuery - Google Cloud Function Error - PubSub to BigQuery 如何在谷歌云中保存一些规则或配置,然后调用它来处理云函数中的发布订阅主题数据? - How can I save some rules or config in google cloud and then call it to process a pubsub topic data in cloud functions? Google PubSub - 统计主题中的消息 - Google PubSub - Counting messages in topic Google Cloud PubSub - 如何将多个 arguments 发送到云端 Function - Google Cloud PubSub - How to send multiple arguments to the Cloud Function Google Cloud Tasks 对转发到 Cloud Functions 执行速率限制? - Google Cloud Tasks enforcing rate limit on forwarding to Cloud Functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM