birnbaum
birnbaum

Reputation: 4946

Measure AWS Lambda startup duration

I am currently collecting and logging performance metrics of my function and the only metric I am missing is the startup duration (my function is pretty large, about 35MB compressed). I really need to know how long the startup takes and, even more important, how often it occurs (I have the feeling it is occurring way more often since my concurrent executions limit has been raised).

Is there any way to retrieve this information in Lambda? Or can someone think of a possibility to pass the current timestamp of an API Gateway call via e.g. the mapping template, so I can compute the startup time by myself?

Upvotes: 10

Views: 9484

Answers (4)

Jha Nitesh
Jha Nitesh

Reputation: 388

The answer is already listed, I am just showing it in a better format.

filter @type="REPORT" and ispresent(@initDuration)
| stats count() as coldStarts, avg(@initDuration), min(@initDuration), max(@initDuration) by bin(5m)

Upvotes: 5

Mehul Karia
Mehul Karia

Reputation: 71

Try this in Log insights Cloudwatch for a Lambda function:

fields @timestamp, @initDuration

    | filter @type = "REPORT"
    | sort @timestamp desc

Upvotes: 7

priyesh.patel
priyesh.patel

Reputation: 196

AWS has recently introduced a Init Duration in cloudwatch logs alongside Billed Duration log for measuring a cold start lambda's before the actual invocation begins.

From the "Report" section inside Lambda Log Stream

Here's a sample log from one of my lambda -

Duration: 1200.50 ms 
Billed Duration: 1300 ms 
Memory Size: 3008 MB 
Max Memory Used: 308 MB 
Init Duration: 4317.73 ms

Upvotes: 16

RyanG
RyanG

Reputation: 4152

There's no deterministic way to measure function startup time right now. At this time, your best bet would be to enable CloudWatch Logs for your API, and process the timestamps of the log events. It should be pretty obvious which calls trigger a function initialization as the time delta between the events before and after calling Lambda would be significantly higher than the average. Based on this you could generate some statistics on the ratio of initializations, and the average initialization time.

Thanks, Ryan

Upvotes: 1

Related Questions