Skip to content

Fix/lambda cold start - #1

Merged
ErnestTorz merged 4 commits into
mainfrom
fix/lambda-cold-start
Oct 30, 2026
Merged

ErnestTorz merged 4 commits into
mainfrom
fix/lambda-cold-start

Conversation

@m-messer

Copy link
Copy Markdown
Member

See the commits for more detail, but changed the transport layer and lazy loaded large imports.

m-messer and others added 4 commits October 30, 2026 10:28
Import ultralytics lazily on first evaluation so the IPC server opens
its socket inside Lambda's 10 s init window, and install CPU-only
torch/torchvision on Linux to drop the multi-GB CUDA libraries from the
image. Also bump Poetry in the Dockerfile to 2.x to match poetry.lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker still took 12.7 s to open its IPC socket on Lambda, past the
10 s init limit. cv2 and numpy were the largest remaining module-level
imports and are only needed for drawing, so import them there and
compute the timing averages without numpy.

Also run compileall after copying the function code so it is
precompiled too; Lambda's read-only filesystem can't cache bytecode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the ipc transport, shimmy holds Lambda's 10 s init open until the
worker has created its socket, which the Python imports still couldn't
do on a cold container. Deferring the torch import only moved that cost
into the first request, which then hit the 30 s FUNCTION_TIMEOUT.

Use stdio like eduVisionAeroRC instead: init returns immediately and the
request waits on stdin while Python imports. Restore the module-level
ultralytics, cv2 and numpy imports and preload the default model so that
work overlaps the cold start rather than the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first request after a cold start still hit shimmy's 30 s send
timeout while Python was importing torch/ultralytics. Raise it to 90 s,
and temporarily enable PYTHONPROFILEIMPORTTIME so CloudWatch shows which
imports dominate the cold start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer requested a review from ErnestTorz October 30, 2026 13:10
@ErnestTorz
ErnestTorz merged commit d2e3a4e into main Oct 30, 2026
10 checks passed
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.

2 participants