2

I have a lambda that keep experiencing cold start. I configured the lambda to have 5 provisioned concurrency, as it was suggested as a possible solution, but the lambda still have cold starts.

What might be a possible explanation? Maybe 5 provisioned concureency is not enough? (how can I know what will be a good amount of containers?)

How did you handle cold start?

Also, a very important question: how can I be sure it uses my lambdas? where can I monitor it?

thanks!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Sharon
  • 53
  • 7
  • if you can't tolerate any cold start you would have to provision your concurrency to the max concurrency of the lambda. do you ever run the lambda more than 5x at once? Does it correspond with the cold start? Are you sure you're experiencing cold start at all, and not just slow lambda code? – erik258 Oct 02 '22 at 13:24
  • @erik258 thank you for your response. I see in datadog that I get many cold starts, that how datadog identifies the initialization of the lambda (at least 4 minutes to init). How can I know for sure I am expriencing cold start and not just slow lambda cold? what can be a good indication for it? t – Sharon Oct 02 '22 at 13:36

2 Answers2

0

Some possible directions to avoid cold starts:

  1. try to keep the lambdas warm - by scheduling a ping call to a dummy method every 1 minute or so
  2. check your code - cold start happens due to a lot of code/libraries being loaded into memory when the function starts. Try loading only the minimal possible when the function is invoked, and load any additional libraries dynamically only when they are required. (You can do that by using require('your-lib-name-here') in node.js or via reflection in C#)
LiriB
  • 814
  • 8
  • 12
0
  1. You can definitely try the steps given by LiriB to optimize the cold start.

  2. Also, you can monitor the the metrics for Invocations which will give you the clue of total Invocations: Here is one of the sample code for metric:{ "metrics": [ [ "AWS/Lambda", "Invocations", "FunctionName", "dataservice-funct-getclaimfreqpred", "Resource", "function_name:alias", { "color": "#2ca02c" } ], [ ".", "ConcurrentExecutions", ".", ".", ".", ".", { "color": "#9467bd" } ], [ ".", "Errors", ".", ".", ".", ".", { "stat": "Average", "color": "#ff7f0e" } ], [ ".", "Duration", ".", ".", ".", ".", { "stat": "Average", "color": "#1f77b4" } ] ], "view": "timeSeries", "stacked": false, "region": "region_name", "stat": "Sum", "period": 300, "title": "title" }

  3. Additionally you can follow the auto-scaling-provisioning for auto-scaling