Lambda has performance issue

0

We have an issue with our Lambda Runtime Node.js 14 and 128MB, until one month ago was working fine, that means Duration was under one second. Now, sometimes is working slowly (Duration 12 seconds) and sometimes with the same request is working smoot (Duration 0.5 seconds). On my local machine is always working fine, so I increased the Memory from 128MB to 512MB but the issue persist. What else can I check ?

Edit: The lambda is connecting to other AWS services, Secrets Manager, Postgres, SES. All of them are taking up to 4 seconds each in one session. All of these services are in the same region of AWS

2 Answers
1

What is your Lambda function doing? Is it calling external APIs? Could it be that those are causing a delay that you're seeing?

Without knowing what the code is doing it's not easy to provide advice.

If it were me I would be using some sort of logging or tracing inside the code to see where the delays are happening.

profile pictureAWS
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • The lambda is connecting to other AWS services, Secrets Manager, Postgres, SES. All of them are taking up to 4 seconds each in one session. I've updated initial post

  • In that case my advice is the same: put some instrumentation/logging into your function to see where the delay is coming from.

  • Yes, we've already did this, simple post request to SES with AWK SDK .NET takes 4seconds sometimes, other times takes 0.1seconds. When this is happening all other AWS services request takes a lot of time. Opening a connection to Postgres DB, getting secrets from Secrets Manager

  • Ok - what is the cause of the extra time? Is it DNS lookup? Is it because there are multiple IP addresses in the DNS reply and the first does not respond? Is it something to do with TLS negotiation?

1

Hello.

How about setting up provisioned concurrency?
Perhaps your Lambda is running slower due to cold starts.
Setting provisioned concurrency helps reduce cold start latency.
https://docs.aws.amazon.com/lambda/latest/dg/provisioned-concurrency.html

Provisioned concurrency – This is the number of pre-initialized execution environments allocated to your function. These execution environments are ready to respond immediately to incoming function requests. Provisioned concurrency is useful for reducing cold start latencies for functions. Configuring provisioned concurrency incurs additional charges to your AWS account.

Also, although this is not very relevant, Node.js14 is a deprecated runtime, so I recommend updating to a newer runtime version if possible.
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtimes-deprecated

profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • I updated the runtime to Node.js 20 and now the latency seems to be more frequent. Why should I configure provisioned concurrency, since worked just fine ?

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