Understanding aws sqs NumberOfEmptyReceives metric

0

Hello team, I will like to better understand the empty receives metric on SQS to be able to optimize cost. I have an sqs queue which serves as a trigger to a lambda function. If my wait time seconds is 5 seconds (long polling enabled), I expect the queue goes to ReceiveMessage from the producer with no message returned. If it waits 5 seconds when there are no messages for a whole minute, I expect that the empty receives should not be more than 12 in a minute but I am having as high as 35 empty receives per minute during peak periods and as low as 6 empty receives per minute during low activity period. I have gone through the documentation but havent gotten a full understanding of how this works

1 Answer
2
Accepted Answer

When you use Lambda as the consumer, we actually use 20 seconds for the Wait parameter, so you should actually see lower numbers. However, we start polling the queue with 5 pollers and when there are more messages, we increase the number of pollers up to 1000. This is why you see higher numbers than what you expect.

If you will try it with an empty queue, you should probably see 15 empry receives per minutes (5 pollers, each at 3 times per minute).

profile pictureAWS
EXPERT
Uri
answered 2 months ago
profile picture
EXPERT
reviewed a month ago
  • Additionally, you can adhere to best practices for message handling by setting up long polling. This approach is detailed in the Setting up long polling section, where you'll find strategies to optimize efficiency and reduce costs.

  • Thanks Uri, when the queue is empty, I get 6 empty receives per minute. Please can you refer me to where I can get more info on this? I am still not clear on your response, does this mean I do not have to set wait parameter for my fifo queue when using lambdas as consumers because it is already set that way? Meaning updating the wait parameter wont make any difference? I really need to know.

  • True. Lambda always uses 20 seconds, regardless of how your configured the queue. You can find more information here.

    Why do you really need to know? How does this affect your application?

  • Because I am looking for ways to optimize cost. Long polling and batching seem to be the only options to do this, batching 10 messages per batch is enabled for lambda invocations, same as long polling and we still have that number. This is really costing us

  • You are correct that long polling and batching is a way to reduce cost. But for your information, if you do the math, for an empty queue, 5 pollers * 3 / min * $0.40 /mil requests gets you to $0.26 per month per queue. Not very expensive.

    You can increase the batch size if you want to reduce the cost for Lambda. Although SQS only supports batches of up to 10 messages, Lambda can batch much larger and invoke your function with 1000s of messages per invoke.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions