为什么 NumberOfMessagesDeleted > NumberOfMessagesSent
Why is NumberOfMessagesDeleted > NumberOfMessagesSent
我不了解我正在查看的 SQS 非 FIFO 队列(下图)的指标,因此我希望有人可以帮助我。所附图片显示了我如何配置指标,以及发送的消息数和在此 SQS 队列的生命周期内删除的消息数的总和(队列不到 1 周,但我设置了指标周期2 周)。
我的理解是NumberOfMessagesSent
是指成功入队的消息数,NumberOfMessagesDeleted
是指成功出队的消息数。鉴于这种思路,我认为 NumberOfMessagesDeleted
应该总是 <= 而不是 NumberOfMessagesSent
但事实显然并非如此。
我在这里错过了什么?
对于您使用的每条消息,您都有一个 receipt handle。您可以多次使用此句柄调用 DeleteMessage
,这些调用已成功记录,增加了 NumberOfMessagesDeleted
指标的值。
事实上 AWS docs 提供了 2 个示例,什么时候 NumberOfMessagesDeleted
会比预期的更大:
- 如果同一队列有多个消费者:
If the message is not processed before the visibility timeout expires, the message becomes available to other consumers that can process it and delete it again, increasing the value of the NumberOfMessagesDeleted
metric.
- 为同一条消息多次调用
DeleteMessage
:
If the message is processed and deleted but you call the DeleteMessage
action again using the same receipt handle, a success status is returned, increasing the value of the NumberOfMessagesDeleted metric.
如果您的代码中存在错误,则可能会出现第二种情况。比如使用的库收到消息后自动删除,但是你也尝试手动删除消息
此外,非FIFO SQS队列可能会遇到消息重复,这也会增加删除的消息数量。
我不了解我正在查看的 SQS 非 FIFO 队列(下图)的指标,因此我希望有人可以帮助我。所附图片显示了我如何配置指标,以及发送的消息数和在此 SQS 队列的生命周期内删除的消息数的总和(队列不到 1 周,但我设置了指标周期2 周)。
我的理解是NumberOfMessagesSent
是指成功入队的消息数,NumberOfMessagesDeleted
是指成功出队的消息数。鉴于这种思路,我认为 NumberOfMessagesDeleted
应该总是 <= 而不是 NumberOfMessagesSent
但事实显然并非如此。
我在这里错过了什么?
对于您使用的每条消息,您都有一个 receipt handle。您可以多次使用此句柄调用 DeleteMessage
,这些调用已成功记录,增加了 NumberOfMessagesDeleted
指标的值。
事实上 AWS docs 提供了 2 个示例,什么时候 NumberOfMessagesDeleted
会比预期的更大:
- 如果同一队列有多个消费者:
If the message is not processed before the visibility timeout expires, the message becomes available to other consumers that can process it and delete it again, increasing the value of the
NumberOfMessagesDeleted
metric.
- 为同一条消息多次调用
DeleteMessage
:
If the message is processed and deleted but you call the
DeleteMessage
action again using the same receipt handle, a success status is returned, increasing the value of the NumberOfMessagesDeleted metric.
如果您的代码中存在错误,则可能会出现第二种情况。比如使用的库收到消息后自动删除,但是你也尝试手动删除消息
此外,非FIFO SQS队列可能会遇到消息重复,这也会增加删除的消息数量。