Unexpected behavior when using lambda batch window

0

Hi,

We have async lambda function that reads from SQS events.

We run this lambda for long time with batch size = 10 and batch window = 0, and process time was ~ 3 seconds.

As we need to increase batch size to 100 we also changed batch window to 1, expecting to see increase of 1-2 seconds in process time with the same load of events, but when tested we saw that process time was ~ 20 seconds.

Why is this behavior happen ? How could we reduce process time with large batch size configuration ?

Thanks,

asked 7 months ago532 views
3 Answers
1

Hello, Matan Erez.

Here's what you can do to potentially reduce the processing time with a larger batch size:

Concurrency Settings: Consider adjusting the concurrency settings for your Lambda function. You can either increase the concurrency to handle more invocations in parallel or experiment with different batch sizes and batch window settings to find the optimal balance for your specific use case.

Throttle SQS Queue: If the SQS queue is a bottleneck, you may need to consider adjusting the SQS queue's configuration. For example, you can adjust the queue's visibility timeout, message retention period, and the number of inflight messages to better match the processing capacity of your Lambda function.

Asynchronous Processing: If it's feasible for your application, you might consider asynchronous processing with a fan-out pattern. In this approach, you use an SQS queue to collect incoming events and then trigger multiple Lambda functions to process the messages concurrently. Each Lambda function can handle a smaller batch size, which may lead to more predictable and faster processing times.

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
1

When you increase the batch size it means your function will receive more records. If it takes your function 3 seconds to process 10 records, it makes sense that it will take the function 20 seconds to handle 100 records.

Window size has nothing to do with processing time. It controls how long should the Lambda service wait for the batch to fill before invoking your function. If you set your batch window to 10 seconds and the batch size to 100, Lambda will wait up to 10 seconds, or 100 records, before invoking your function.

If you want to reduce the processing time of a large batch, you can use threads inside your function, each thread processing a subset of the records.

profile pictureAWS
EXPERT
Uri
answered 7 months ago
0

As previously mentioned, you increased the batch size from 10 to 100 which means you increased it to 10 times the original size. If it took 3 seconds to process 10 then each record takes approximately 300 milliseconds to process each record (10 * 300 ms = 3,000 ms = 3 seconds). Theoretically, it would now take 30 seconds to process 100 (100 * 300 ms = 30,000 ms = 30 seconds).

answered 7 months ago

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