AWS Lambda + SnapStart - Slow First Request

0

We are experiencing a slow response to the first request, although SnapStart is enabled.

Slow First Request

Fast Subsequent Request

The method "getCustomer" requests user information from an AWS RDS Database, Database reconnection is handled in the after-restore hook. This takes around 200ms of the 600ms restore-phase total, as indicated by logs.

I was already suspecting some kind of class-loading / JIT performance impact, and used the pre-snapshot hook to perform a request against the database to ensure everything is loaded before snapshot creation, but still this doesn't seem to fix the issue. Any idea how to get a snapshot with a fully initialized lambda (as it seems preferrably one that already handled a request), or what might be the issue that is causing this delay?

Thanks in advance.

Domi
asked 9 months ago372 views
1 Answer
0

Hi Domi.

I found the following Blog post that discuss Lambda performance optimizations. From this post, I would recommend you consider investigating about Provisioned Concurrency:

If you need predictable function start times for your workload, Provisioned Concurrency is the recommended solution to ensure the lowest possible latency. This feature keeps your functions initialized and warm, ready to respond in double-digit milliseconds at the scale you provision. Unlike on-demand Lambda functions, this means that all setup activities happen ahead of invocation, including running the initialization code.

Just to confirm, have you gone through the features and limitations of SnapStart? SnapStart is only supported on specific regions, and, per the documentation:

SnapStart supports the Java 11 and Java 17 (java11 and java17) managed runtimes. Other managed runtimes (such as nodejs18.x and python3.11), custom runtimes, and container images are not supported.

SnapStart does not support provisioned concurrency, the arm64 architecture, Amazon Elastic File System (Amazon EFS), or ephemeral storage greater than 512 MB.

To work with SnapStart, you can use the Lambda console, the AWS Command Line Interface (AWS CLI), the Lambda API, the AWS SDK for Java, AWS CloudFormation, AWS Serverless Application Model (AWS SAM), and AWS Cloud Development Kit (AWS CDK). For more information, see Activating and managing Lambda SnapStart.

Also: You can use SnapStart only on published function versions and aliases that point to versions. You can't use SnapStart on a function's unpublished version ($LATEST).

I hope this helps.

profile pictureAWS
EXPERT
answered 9 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