-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: High init duration when deployed through SAM. #6715
Comments
Hi, I was not able to reproduce your slow cold start with a project deployed via SAM CLI: SAM CLI
HelloWorldLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./layer
CompatibleRuntimes:
- python3.11
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.11 The only thing that is inside of
EphemeralStorage:
Size: 512
Layers:
- !Ref HelloWorldLayer
AWS CLIWhen creating a Lambda manually via the AWS CLI:
Inspecting the Cloudwatch logs for the function, we can see that the init time is roughly the same as one the one deployed with SAM CLI:
Is there a reproducible project that you can share somewhere where we can reproduce this? Something interesting to point out, is that in your function runtime logs it looks like the memory is being maxed out. This may have something to do with the slow init times? |
Found the issue. It was because of same module importing twice in a python file which was in the layer.
removed second line. Then init duration during warm up reduced from 5s to 0.5s. Also Max Memory Used gone down from 250MB to 70MB. |
Hi @AmruthjithSunil, glad you found the issue. Does that address your concerns when running sam commands now? |
Closing as the issue seems to be resolved. |
|
Description:
When deployed through sam the init duration is very high(5s) but when we deploy manually it takes less than 1s. Functionally its working fine in sam deployment. Only issue is the high init duration. We changed only layers in sam with the layer we had in manual deployment then it was working as expected(low init duration).
Steps to reproduce:
sam deploy commands:
1 sam build --use-container -t ./template.yaml
2 sam deploy --config-env prod
with and without docker(--use-container) we tried
We have 3 more custom util py files in layer.
template.yaml
We tried both arm and x86 architectures and different python versions.
requirementes.txt
Observed result:
Test Event Name
test
Response
{
"statusCode": 200,
"status": "success",
"headers": {
"Access-Control-Allow-Origin": "*"
},
"messages": "[]"
}
Function Logs
START RequestId: 6ae5c841-833f-4d0a-abd1-dcf4c19ec834 Version: $LATEST
[INFO] 2024-02-20T06:51:59.375Z 6ae5c841-833f-4d0a-abd1-dcf4c19ec834 Received event: {
"user_id": "9fcb1fec0d522dcfcfaeb64da8d30b4a",
"organization_id": 11
}
END RequestId: 6ae5c841-833f-4d0a-abd1-dcf4c19ec832
REPORT RequestId: 6ae5c841-833f-4d0a-abd1-dcf4c19ec834 Duration: 15.53 ms Billed Duration: 16 ms Memory Size: 256 MB Max Memory Used: 256 MB Init Duration: 4970.89 ms
Request ID
6ae5c841-833f-4d0a-abd1-dcf4c19ec832
Expected result:
Init Duration should be less than 1000ms
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.109.0The text was updated successfully, but these errors were encountered: