Description
Description
We recently upgraded our New Relic layers, and this appears to have resulted in a massive slow-down in our cold start times, with the time from AWS's START
log line to "our code executing" going from 100-200ms to 5-10s, and this is entirely with New Relic.
For instance, we don't see this slowdown if we set the lambda to call our handler directly (not going via newrelic_lambda_wrapper.handler
+ NEW_RELIC_LAMBDA_HANDLER
).
We're in ap-southeast-2
(Sydney), and are using layers like arn:aws:lambda:ap-southeast-2:451483290750:layer:NewRelicPython310:17
. Comparing versions (i.e. changing 17
) with a lambda with 256MB of memory, we find the interesting start times are:
version | start time |
---|---|
17 | 5.5-5.6 |
16 | 5.5-5.6 |
15 | 6.8-7.3 |
14 | 7.2-7.5 |
13 | 10.0-10.1 |
... | (similar) |
8 | ~10 |
7 | ~1.4 |
... | (similar) |
2 | ~1.5 |
1 | 0.1-0.2 |
In summary:
- 1 -> 2: slow-down
- 7 -> 8: slow-down
- 13 -> 14: speed-up
- 15 -> 16: speed-up
The final result is still a massive slowdown from where it used to be. This causes issues for us. For instance, lambda hooks for cognito have a strict 5 second time limit... and the initialisation time alone exceeds that, even without running any real code (we do use provisioned concurrency, but we want to have functional Lambdas, even if we get a spike in load that exceeds the provisioning).
When Amazon Cognito calls your Lambda function, it must respond within 5 seconds. If it doesn't and if the call can be retried, Amazon Cognito retries the call. After three unsuccessful attempts, the function times out. You can't change this five-second timeout value — https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html#important-lambda-considerationsl
Steps to Reproduce
- Create a large lambda (sorry, quite a lot of effort to narrow down the specifics, our lambdas include boto3 and sqlalchemy) with a new relic layer, that prints something as soon as the "real" code starts executing
- Invoke it
- BUG: observe there's a long time between AWS's
START
and the printing of the real code
Expected Behaviour
Start-up times like they used to be: a few milliseconds, not a few seconds.
Relevant Logs / Console output
Using one of the layers between version 8 and 13, with a lambda that has print("Starting function...")
at the top of the real handler, the CloudWatch logs include something like:
2024-01-09T12:28:56.259+11:00 START RequestId: ad0b4e84-98db-46e3-96c6-f9f28b20e2b2 Version: $LATEST
2024-01-09T12:28:57.272+11:00 [NR_EXT] Sent 1/1 New Relic function log batches successfully with certainty in 517.487ms (516ms to transmit 0.3kB).
2024-01-09T12:29:06.353+11:00 Starting function...
Note how the start line is at 28:56.259
while the print
happens at 29:06.353
, more than 10s later.
Your Environment
AWS Lambda, Python 3.10, layer versions above.
Additional context
I imagine this may be caused by changes to the underlying agents, but I can't work out how to find the version of the agent that's included in a particular layer, e.g. it doesn't appear to be logged by the init routine.