- Newest
- Most votes
- Most comments
Hello, I mixed my answers with your questions hoping this would be easier to read.
Q) Is 3800ms a normal cold start time? A) Cold starts are impacted by the runtime and Lambda function's dependencies. A normal cold start time really depends on what the Lambda function is doing. The less the Lambda function does during the init duration, the shorter the cold start. If you wanted to see the impact of the docker container on cold start, you can create a Lambda function that just prints "hello world" and gather benchmarks.
Q) In my new pipeline why is it not improving the init duration? A) It isn't very clear if your Lambda function is still experiencing cold starts or not. You could use CloudWatch Insights to query the logs for your Lambda function and generate a report on cold starts. Here is an example of a query you could use:
filter @type = “REPORT”
| stats count(@type) as countInvocations,
count(@initDuration) as countColdStarts,
(count(@initDuration)/count(@type))*100 as percentageColdStarts,
max(@initDuration) as maxColdStartTime,
avg(@duration) as averageDuration,
max(@duration) as maxDuration,
min(@duration) as minDuration,
avg(@maxMemoryUsed) as averageMemoryUsed,
max(@memorySize) as memoryAllocated, (avg(@maxMemoryUsed)/max(@memorySize))*100 as percentageMemoryUsed
by bin(1h) as timeFrame
You can use this to compare the two pipelines. You can also use X-Ray to trace the Lambda function and the X-Ray daemon records a segment with details about the function invocation and execution.
Q) What approach do you recommend to reduce/fix the cost? There are three areas you could look at:
- If your Lambda function is still impacted by cold starts, you can use Reserved Concurrency to limit how many concurrency instances of the function can run. If I understand your workload, this is the same Lambda just receiving different parameters so you can use Reserved Concurrency to ensure 200 instances of the function aren't created. You'll want to test our different maximum number of concurrent instances to find what best meets your requirements around cost and speed.
- Make sure you are optimizing static initialization.
- Profile the function with AWS Lambda Power Tuning to ensure you are using the most cost and/or performant memory configuration.
Init Duration is just for First Call, it didn't affect Nth call. i recommend try time() and print() functions between your imports and start of the code. maybe the problem is not relevant to lambda environment itself.
Thanks for your answer @matthew_d it was very helpful ! I also found this great article that also answer all my questions : https://aws.amazon.com/fr/blogs/compute/operating-lambda-performance-optimization-part-1/#:~:text=If%20you%20see%20cold%20starts,alias%20with%20Provisioned%20Concurrency%20configured
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago