Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is my Lambda doing between startup and first line?

I have some Lambda functions written in C# running in the .NET Core 2.1 runtime in AWS. The cold start time on them is very large (>8s with 256MB, >4s with 512).

However, I'm not sure if it is just cold start time or something else; I have other lambdas that are written in dotnet and they seem to have shorter startup times.

An X-Ray trace shows a big gap between "Initilization" being completed and anything happening. I start an X-Ray subsegment on the first line of my handler (seen in the trace as "Configure").

Is there something I'm missing?

AWS X-Ray trace

like image 514
Tom Davies Avatar asked Jul 12 '18 19:07

Tom Davies


People also ask

What causes Lambda cold starts?

Lambda cold starts occur when there is no available function instance to respond to an invocation. This can happen when instances have expired due to inactivity or when there are more invocations than active instances.

What is cold start and warm start in Lambda?

Lambda functions run inside containers that AWS must spin up before the function can execute its task. This prep time means it can take a while before the code runs. This is called a cold start. Other times, the container is up and available, and the Lambda function runs right away. This is a warm start.

What is Lambda Cold Start time?

The duration of a cold start varies from under 100 ms to over 1 second. Since the Lambda service reuses warmed environments for subsequent invocations, cold starts are typically more common in development and test functions than production workloads.


1 Answers

The "?" in the image you provided is Lambda system code.

The "initialization" segment includes running the constructor and static blocks for your function. But it also includes some reflection on your assembly to validate and find your function class and constructor. It also finds and validates your serializer, if you're using one.

I can't give a definitive answer as to why this function is behaving differently from other functions. Could you show some graphs of the functions you're comparing to with descriptions of the functions (memory, what the functions are doing, what dependencies are in the zip package)?

like image 193
jvellocitty Avatar answered Sep 20 '22 13:09

jvellocitty