-
Notifications
You must be signed in to change notification settings - Fork 365
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
Coldstart can be drastically reduced by calling LambdaHandler externally #982
Conversation
Test code is failing because |
I'm really interesting in this feature. |
@Yaronn44 I'm not sure because I didn't capture it, but it's definitely less than 1k |
The invocation number is meaningless btw |
How does it work under the hood ? Why does calling the class like that improve the perfs ? |
I don't know the detailed principle, but there seems to be some delay in the first invocation after the cold start. |
I need help to pass the test. |
@Yaronn44 The "execution context" is kept around for subsequent lambda invocations: See "Take advantage of execution environment reuse to improve the performance of your function": I've had an issue with zappa opening too many simultaneous database connections so I'm hoping that this feature will solve that problem |
Oh, I didn't see that singleton stuff at the top of the |
@xncbf If you check x-ray in api gateway, you can see this commit is not working. If you are using |
@MunsuPark I've tried several things. |
In addition, I forked this branch and applied it to the production environment and have been using it for a week. There are a few other minor issues, but the cold start has definitely been reduced. The following is the duration graph for the last 4 weeks. |
I'd really love to see that feature out 🙂
You could do something like:
This would become something optional through the ENV variables 🤷 WDYT ? |
I received a personal email from @MunsuPark on June 3rd stating that my commit was wrong. This is my 6 hour x-ray -lambda-function (still have coldstart.) This is the log of api-gateway before commit is applied. This is the api-gateway log up to now after commit is applied. |
I've been running a custom fork with a Perhaps adding a configurable setting is the most conservative approach for now? The default behavior could be off, but allow users to enabled it if desired. Over time we could do more testing and change the default behavior. This PR would need a quick documentation update - perhaps something like the following:
|
This change greatly reduces the Lambda cold start time in a project I am working on as well, by about 6 seconds. A configurable setting should work. |
Is there any update on this issue? Our project has reached own patch like same solution and drastically reduced duration for lambda with provisioned concurrency. Deploy this fix at about 18:20 and disappear spike by cold start with initialization. Lambda durationAPI Gateway latencyIMO, This PR is very useful if target lambda is configured with provisioned concurrency. As a result, first invocation is slow even with provisioned concurrency. |
I just edited code by request. plz check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
…ly (zappa#982) * ADD: LambdaHandler outside * UPDATE: apply to INSTANTIATE_LAMBDA_HANDLER_ON_IMPORT variable Co-authored-by: Will Boyce <[email protected]>
Description
Coldstart can be drastically reduced by calling LambdaHandler externally.
Before
After
GitHub Issues
Miserlou/Zappa#1974
#810