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

Package size exceeding lambda limits #56

Closed
emileten opened this issue Apr 23, 2024 · 9 comments · Fixed by #74
Closed

Package size exceeding lambda limits #56

emileten opened this issue Apr 23, 2024 · 9 comments · Fixed by #74
Assignees

Comments

@emileten
Copy link
Contributor

I tried deploying this package as is to AWS lambda following the procedure in infrastructure/aws -- namely, deploying the package as a zip file in S3 which is then pulled by the lambda. I am getting an error due to the size of the unzipped package exceeding the limit of 262 MB -- I am at 263 MB.

One solution could be to switch to a docker-container based lambda but this is going to make the application slower. Instead, we could make the redis dependencies optional.

I am also suggesting that we pin more aggressively the package versions so as to prevent package size increase in the future -- which is what caused this issue (in the first place this package wasn't exceeding the size limit, and I guess that since then some of our dependencies increased in size and we hadn't pinned them).

What do you think of the latter?

@vincentsarago
Copy link
Member

The current dev deployment is blocked by this.

There could be three solutions:

@abarciauskas-bgse
Copy link
Contributor

FYI @hrodmn since I know you are working on this. I'm going to assign it to you for now but we can close it and open a new issue if you prefer.

@hrodmn
Copy link
Contributor

hrodmn commented Jan 13, 2025

In #74 I was able to create a Lambda package that was ~230 MB, but that was without the --compile-bytecode flag in the uv pip install command:

When I do set --compile-bytecode the package size is inflated by the compiled .pyc files that are created. I do not know the exact impact pre-compiling has on Lambda application startup time, but I think it is probably worth the extra megabytes in the package size (as long as we are still under).

@vincentsarago
Copy link
Member

I do not know the exact impact pre-compiling has on Lambda application startup time

I don't think the impact is huge, that's an nice option 👍

@hrodmn
Copy link
Contributor

hrodmn commented Jan 13, 2025

Another way to reduce the Lambda package size is to run strip *.so on the /asset directory:

RUN find /asset -type f -name '*.so' -exec strip {} \;

This command strips debug information from the compiled C/C++ extensions. With this change alone I can bring the Lambda package size down to 204 MB. If we strip and drop the --compile-bytecode flag the package size gets brought down to 180 MB.

I tested out the strip command on my local virtual environment and the pytest tests still pass.

@vincentsarago
Copy link
Member

I think I had issue in the past with the strip command once running it in Lambda

@hrodmn
Copy link
Contributor

hrodmn commented Jan 13, 2025

I think I had issue in the past with the strip command once running it in Lambda

Thanks for the heads up! I did some testing with the titiler docker image and the container failed to start with an ImportError for numpy when I stripped all *.so* files.

After some testing it appears that if we leave the *.so* files from numpy.libs alone, everything* works.

*everything: the container can start, I can render tiles for a COG from the internet (url=https://github.com/GeoTIFF/test-data/raw/8506204783ff26a6c49ed1f721e7e1635b2e43ee/files/GA4886_VanderfordGlacier_2022_EGM2008_64m-epsg3031.cog)

@vincentsarago
Copy link
Member

This is great 🙌

we should apply this on other projects 🙏

@abarciauskas-bgse
Copy link
Contributor

Nice thank you @hrodmn

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 a pull request may close this issue.

4 participants