Skip to content
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

support async init for long initialization lambda functions #53

Merged
merged 5 commits into from
Jul 27, 2022
Merged

Conversation

bnusunny
Copy link
Contributor

Issue #, if available:

Close #35

Description of changes:

support async init for high cold start lambda functions

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@bnusunny bnusunny requested review from calavera and ferdingler July 24, 2022 04:13
@bnusunny bnusunny changed the title support async init for high cold start lambda functions support async init for long initialization lambda functions Jul 24, 2022
) -> Result<Response<Body>, Error> {
// continue checking readiness if async_init is configured and the app is not ready
if options.async_init && !is_app_ready {
check_readiness(options).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to add an extra request to the server in every call in this case, even after the server is ready, isn't it? For example, if the same micro-vm serves two requests, one after the other, both of them check if the server is ready, even when we already know that it's ready after the first one.

It might be better to implement a dedicated Tower service as a handler that can keep that state, so any requests after the first one don't need to check if the server is ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I have a simple fix for it.

@bnusunny bnusunny requested a review from calavera July 25, 2022 15:54
@bnusunny bnusunny merged commit f9a9adf into main Jul 27, 2022
@calavera calavera deleted the dev branch July 27, 2022 23:28
@CGarces
Copy link

CGarces commented Oct 16, 2022

Why ASYNC_INIT is not enabled by default?
What are the disadvantages?

@bnusunny
Copy link
Contributor Author

Only managed runtimes have the 10 seconds limit. Customs runtimes and OCI images do not have this limit. And it's better to have an explicit opt-in to make sure people understand this is not a default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for long running initialization
3 participants