What configuration options can be adjusted to reduce the latency?

# Reducing AWS Lambda Triggered by SQS Latency

There are a few configuration options that can help reduce latency when using an Amazon SQS queue as a trigger for an AWS Lambda function:

  1. Increase the batch size – The default batch size is 10 messages. Increasing the batch size can reduce the number of Lambda invocations, which in turn reduces latency. You can configure a batch size of up to 10,000 messages for standard queues and 10 messages for FIFO queues.
--batch-size 100
  1. Increase the batch window – The default batch window is 0 seconds. Increasing the batch window allows Lambda to collect more messages before invoking your function. This can reduce the number of invocations and latency. You can configure a batch window of up to 20 seconds.
--maximum-batching-window-in-seconds 20
  1. Use long polling – Configure long polling on the SQS queue to reduce empty receives. Lambda will wait up to 20 seconds for a message before timing out. This avoids unnecessary latency from empty receives.
  2. Increase the queue’s visibility timeout – The visibility timeout should be at least 6 times your function’s timeout plus the batch window. This gives Lambda enough time to process batches and retry on errors.
  3. Reduce the function’s timeout – A shorter timeout can help reduce latency for each invocation. However, you’ll need to balance this with having enough time to process large batches.
  4. Configure maximum concurrency – Setting a maximum concurrency limit can help limit the number of concurrent Lambda invocations from an SQS trigger, which may reduce latency.
  5. Enable partial batch responses – Partial responses allow your function to report specific failures in a batch. This can avoid reprocessing the entire batch and reduce latency.
ALSO READ  How To create a Fargate profile into EKS

Hope this helps! Let me know if you have any other questions. I tried to cover the main configuration options that can impact latency when using SQS as a Lambda trigger.

Sources

  1. https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
  2. https://stackoverflow.com/questions/69373596/decrease-throughput-of-aws-lambda-with-sqs-trigger
  3. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-lambda-function-trigger.html

Abhay Singh

I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *