AWS SQS 长轮询不会减少空接收

AWS SQS Long Polling doesn't reduce empty receives

目前,我有一个 AWS SQS 作为我的 AWS Lambda 函数的触发器。

我想实施长轮询以降低成本,因为我已经用完了每月免费套餐的 70%,主要来自空接收。

我尝试通过将队列属性 ReceiveMessageWaitTimeSeconds 更改为 20 seconds:

来设置长轮询

然而,这似乎并没有减少空接收的数量,设置在 11 月 19 日更改,在 2:00 - 3:00 之间。

根据 AWS DocumentationWaitTimeSeconds 优先于队列属性 ReceiveMessageWaitTimeSeconds

Short polling occurs when the WaitTimeSeconds parameter of a ReceiveMessage request is set to 0 in one of two ways:

  • The ReceiveMessage call sets WaitTimeSeconds to 0.
  • The ReceiveMessage call doesn’t set WaitTimeSeconds, but the queue attribute ReceiveMessageWaitTimeSeconds is set to 0.

Note

For the WaitTimeSeconds parameter of the ReceiveMessage action, a value set between 1 and 20 has priority over any value set for the queue attribute ReceiveMessageWaitTimeSeconds.

由于 AWS Lambda 正在接收 SQS 请求,我认为 WaitTimeSeconds 无法配置。

为什么我的长轮询配置在这种情况下不起作用?是我理解错了什么,还是我配置错了?

谢谢!

实际上长轮询 适合您的情况。

5 lambdas * polling / 20 seconds * 3600 seconds in an hour = 900 receives/hour

我认为您错过的是“5 个最小并发 lambda”。这隐含在 Lambda Scaling Behaviour documentation, but is more helpfully and explicitly laid out in the "Additional Information" section of the announcement/deep-dive blog.

When an SQS event source mapping is initially created and enabled, or when messages first appear after a period with no traffic, then the Lambda service will begin polling the SQS queue using five parallel long-polling connections. The Lambda service monitors the number of inflight messages, and when it detects that this number is trending up, it will increase the polling frequency by 20 ReceiveMessage requests per minute and the function concurrency by 60 calls per minute.