Lambda settings - memory & timeout
Is your idea related to a problem? Please describe.
We need to review the settings for the lambda functions memory and timeouts to find the most optimal ones for both the compute and the cost . As far as I see for the custom resource functions we setup the memory to 1664 and timeout to 300 s (5 minutes) although these function only call an API so not sure if this is the optimal setting. For the lambda handling graph ql queries the memory is set to 3 GB and timeout is set to 15 minutes, although the API Gateway max timeout is 29 s, so it doesn't make much sense.
Describe the solution you'd like We can leverage the following to find an optimal values: https://docs.aws.amazon.com/lambda/latest/operatorguide/profile-functions.html https://github.com/alexcasalboni/aws-lambda-power-tuning
@petrkalos @noah-paige thoughts on this?
data.all's user/deployment base is very diverse, from small enterprises with a few users and datasets to large ones with tenths of users so profiling it is gonna be VERY hard as we will have to emulate those difference usages. The way to go here is to ask for statistics (runtimes, max memory used etc) from all the customers and find which value would work best.
Having said that though I do not think the timeout makes any functional or cost difference. We can only try to tune memory (or even make it a CDK option) based on what we collect from the customers. Also there are numerous reports showing that the close your max memory is to the limit the slower your lambda runs and overall it doesn't make any difference to the cost (you use lower limit but it takes longer). Also you have the risk of breaching the limit and then the runtime might kill your lambdas.
Specifically for the graphql backend lambda you are right that since API Gateway is restricting us to 29 seconds we can reduce that limit (we'd appreciate a PR).
Given all the above I do not think we should make any changes here. If you disagree feel free to reopen the issue.
@petrkalos I disagree at least in one topic: what is the point for the lambda handling api request to have a timeout set to 15 mins if max api gateway timeout is 29 s? Anyway user already got a response (timeout) but lambda may be executing up to 15 mins generating the cost which is not the best practice.
Adding to that:
Also there are numerous reports showing that the close your max memory is to the limit the slower your lambda runs
The aim of https://github.com/alexcasalboni/aws-lambda-power-tuning tool is not finding the closest (the lowest) setting for the memory since you can optimise for performance or cost depending on the needs.
Thanks for the inputs both here and offline, I am reopening the issue, we will discuss it internally and report back