Closed LarsKoelpin closed 6 years ago
Hi @LarsKoelpin, looks like the cold start is genuinely timing out after 10 seconds.
the quick fix is obviously to increase the timeout for the Lambda function to 30 seconds. I understand that this cold start time is definitely not desirable. We need to try and figure out where Spring is spending all the time. We have a bunch of cold start tips in the getting started guide. The first thing I would try in your case is replace the @ComponentScan
annotation with direct @Import
statements for the specific classes you need.
Unfortunately the amount of introspection Spring does is counter-productive in a Lambda environment where resources are limited and start time matters. The good news is that with real production traffic cold starts should only impact 1% of less of all requests.
Hey @SAPessi thanks for your response.
As the example is just a part of the app (I tested with my "real" App, in which 30 seconds timeout isn't even suffiecient, so increasing the timeout is obviously not an option). I thought Spring indexing would be enough. I'll try the Import Method for now. Do you think JPA could be the bottleneck here (I'm also shipping H2, which could be as problem aswell)?
However I think it's not related to aws-serverless-java-container and its my own fault, so I'm going to close this issue. If I'm mistaken feel free to reopen this issue.
Hey @LarsKoelpin, I'll keep this open for now as changes to the library may come from this investigation as well as updates to the documentation.
The primary challenge here is that while a Lambda function can have a timeout of 5 minutes, API Gateway has a hard timeout of 30 seconds. In practice, this means that the first request coming in will trigger a cold start in Lambda. However, if your application takes longer than 30 seconds to start, API Gateway will return a 504 error. Meanwhile, in the background, Lambda will finish starting up the app so that following requests will be successful.
This is obviously not ideal so our goal should be to reduce the "cold start" time for your API to less than 30 seconds - ideally much, much less than that.
What have you tried so far?
Hey @SAPessi I updated my Test Application to use a real RDS Postgres instance and removed any h2 related dependencies while using the Import Annotation. Unfortunately had no success, in fact even increasing the timeout to more than 90 seconds (1400mb RAM, 1min 30s timeout).
I don't think the API Gateway should not be a problem, since it is a test event, I guess?
edit: Removing Spring-data-jpa completely reduced startup time to ~500ms
Scenario
I'm trying to migrate my Sprintboot App to AWS Lambda, using aws-serverless-java-container-spring version 1.1.3.
Expected behavior
My Lambda function exits the request.
Actual behavior
It seems like my Spring application gets started, but never handles the request. (https://github.com/LarsKoelpin/springboot-aws-timeout/blob/58c271767a740315e92ad7a16334cabbfc210634/1-configuration/src/main/java/de/lambda/LambdaApp.java#L35 never gets invoked)
Steps to reproduce
I created a repository at https://github.com/LarsKoelpin/springboot-aws-timeout
Full log output
Cloudwatch
Lambda
What I tried
Any help would be appreciated :)