gpt4 book ai didi

amazon-web-services - 限制从 AWS SQS 触发的 AWS Lambda 的并发调用(忽略保留并发)?

转载 作者:行者123 更新时间:2023-12-03 17:25:48 25 4
gpt4 key购买 nike

对我来说,当我开始时,这似乎是一个简单的用例,但结果比我预期的要困难得多。

问题

我有一个 AWS SQS 作为触发工作线程 AWS Lambda 的作业队列。然而,由于工作 lambdas 共享不可扩展的资源,因此将并发运行的 lambdas 的数量限制为(例如)不超过 5 个同时运行的 lambdas 是很重要的。

很简单,根据 Managing Concurrency for a Lambda Function

Reserved concurrency also limits the maximum concurrency for the function, and applies to the function as a whole



但是,设置 Reserved concurrency -property to 5 似乎被 SQS 完全忽略了,队列 Messages in Flight -property 在我的案例中显示接近 20-30 个并发执行,具体取决于放入队列的消息数量。

问题

我最接近的解决方案是使用 SQS FIFO 队列并设置 MessageGroupId为随机选择或在 1-5 之间交替的值。但是,由于工作负载不均匀,这不是最佳选择,因为最好按实际工作负载而不是偶然分配并发。

我还尝试使用 AWS Step Functions 作为 Map-state有一个 MaxConcurrency 参数,它似乎在小型作业队列上运行良好,但由于每个状态的输入/输出限制为 32kb,这在我的用例中不可行。

有没有人找到更好的或替代的解决方案?还有其他方式吗 Reserved concurrency应该使用?

类似

以下是我发现的一些类似问题,但我认为我的问题有所不同,因为我对限制 total number of invocation 不感兴趣。 ,并且(虽然我自己没有尝试过)我不明白为什么 triggers from S3 or Kinesis Steam会表现得与 SQS 不同。

最佳答案

根据 AWS 文档,AWS SQS 不考虑保留并发。如果要处理的批次数大于保留并发数,则您的消息可能会在死信队列中结束:

If your function returns an error, or can't be invoked because it's atmaximum concurrency, processing might succeed with additionalattempts. To give messages a better chance to be processed beforesending them to the dead-letter queue, set the maxReceiveCount on thesource queue's redrive policy to at least 5.https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html


详情可以查看这篇文章: https://zaccharles.medium.com/lambda-concurrency-limits-and-sqs-triggers-dont-mix-well-sometimes-eb23d90122e0

关于amazon-web-services - 限制从 AWS SQS 触发的 AWS Lambda 的并发调用(忽略保留并发)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61111046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com