Home > Blockchain >  Why is NumberOfMessagesDeleted > NumberOfMessagesSent
Why is NumberOfMessagesDeleted > NumberOfMessagesSent

Time:10-25

I don't understand the metrics for my SQS non-FIFO queue (images below) I'm looking at so I'm hoping someone can help me. The attached images show how I've configured the metrics and are the sum the number of messages sent and the number of messages deleted for the lifetime of this SQS queue (the queue is less than 1 week old but I've set the metrics period for 2 weeks).

It's my understanding that NumberOfMessagesSent refers to the number of messages that have been successfully enqueued and that NumberOfMessagesDeleted is the number of messages that have been successfully dequeued. Given that line of thinking I would think that NumberOfMessagesDeleted should always be <= than NumberOfMessagesSent but this is clearly not the case.

What am I missing here?

enter image description here enter image description here

CodePudding user response:

For every message you consume you have a receipt handle. You can call DeleteMessage using this handle multiple time, these calls are recorded successfully increasing the value for NumberOfMessagesDeleted metric.

In fact the AWS docs provide 2 examples when will the NumberOfMessagesDeleted larger then expected:

  1. In case of multiple consumers for the same queue:

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.

  1. Calling DeleteMessage multiple times for the same message:

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.

The second one may occur if you have a bug in your code. For example, the library used automatically deletes the message after it is received, but you are also attempt to delete the message manually.

Furthermore, non-FIFO SQS queues may encounter message duplications, which can also increase the number of messages deleted.

  • Related