使用谷歌云函数,有没有办法像 AWS Lambda 那样管理执行并发? ( https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html )
我的意图是设计一个使用任务文件并将这些任务发布到工作队列(发布/订阅)的函数。我想要一个函数来消耗工作队列(pub/sub)中的任务并执行任务。
以上可能会导致大量几乎并发的执行。我的下游消费者服务很慢,一次不能消耗很多并发请求。很有可能,它会返回 HTTP 429 响应以尝试减慢生产者的速度。
有没有办法像使用 AWS 那样限制给定 Google Cloud 函数的并发性?
最佳答案
此功能 is not available适用于 Google Cloud Functions。相反,由于您要求处理系统打开并发任务的速度,Task Queues是解决方案。
Push queues dispatch requests at a reliable, steady rate. They guarantee reliable task execution. Because you can control the rate at which tasks are sent from the queue, you can control the workers' scaling behavior and hence your costs.
在您的情况下,您可以控制调用下游消费者服务的速率。
关于concurrency - 如何使用谷歌云函数处理背压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48646777/