aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Feature request: make it possible to keep docker container warm

Open jandockx opened this issue 8 years ago • 81 comments

I understand from other issues that a new docker container is started for each request. This makes some experiments or automated tests undoable in practice. SAM Local is much too slow in the context where more then 1 request is to be handled.

I suspect that hot reloading depends on this feature.

I think it would be a good idea to make it possible to choose, while this project evolves further, to forego hot reloading, but to keep the docker container warm.

Something like

sam local start-api -p <PORT> --profile <AWS PROFILE> --keep-it-warm

This would broaden the applicability of sam local enormously.

Thank you for considering this suggestion. This looks like an awesome project.

jandockx avatar Dec 22 '17 19:12 jandockx

+1 Python container takes too long to start for simple debugging...

aldegoeij avatar Dec 28 '17 09:12 aldegoeij

+1. This currently makes local automated testing painful at best.

Thanks for the continued work on this project!

ghost avatar Jan 05 '18 07:01 ghost

Have there been any eyes on this? The benefit would be so huge.

dannymcpherson avatar Feb 01 '18 22:02 dannymcpherson

+1

cagoi avatar Apr 19 '18 14:04 cagoi

+1

hobotroid avatar Apr 27 '18 15:04 hobotroid

+1

daveykane avatar Jun 04 '18 10:06 daveykane

+1

adrians5j avatar Jun 16 '18 10:06 adrians5j

+1, even a simple hello world java8 lambda takes 3/4 seconds for each request!

CRogers avatar Jun 16 '18 20:06 CRogers

My sketch proposal to make warm containers work and maintain all the existing nice hot reload/memory usage etc functionality around them:

Currently, the container is simply run with handler argument and the event passed in via an environment variable. The containers logs are then piped to the console stdout/stderr and it just records how much memory is used.

Instead, we can start the container with bash as the entrypoint and -c "sleep infinity" as the argument, so it runs effectively nothing and keeps container alive. We record the container id in an (expiring) dict so we can reuse it again. When we want to run the lambda we run docker exec that runs the previously used lambda entrypoint and the correct environment. Since we run one lambda per container we can still record memory usage. If we key the running containers by the version of the lambda code we're running we can ensure hot reload still works. As always with caches the invalidation would be the interesting part - you probably want to kill out of date containers and kill containers when the tool exits.

CRogers avatar Jun 18 '18 12:06 CRogers

+1

monofonik avatar Jul 08 '18 07:07 monofonik

+1 Very interested in this feature

luisvsm avatar Aug 15 '18 01:08 luisvsm

+1 Yes please!

luketn avatar Aug 24 '18 00:08 luketn

+1, throwing my hat in the ring on this too

nodeit avatar Sep 06 '18 02:09 nodeit

As a note: Please use the reaction feature on the top comment. We do look at issues sorted by thumbs up (as well as other reactions). Commenting +1 does not good for that and adds noise to the issue.

jfuss avatar Sep 06 '18 02:09 jfuss

@jfuss I agree (and had done this). Any feedback from your team would be helpful here, though. The closest thing we had to knowing if this is on your radar (before your comment) was duplicate issue consolidation and labeling.

scoates avatar Sep 06 '18 14:09 scoates

+1, this would be very beneficial for people using java + spring boot.

ejoncas avatar Sep 24 '18 08:09 ejoncas

+1, around 1s for golang case

thoratou avatar Oct 06 '18 09:10 thoratou

I did an experiment with container reuse. This is just with a lambda in python, I'm developing on ubuntu 16.04. In summary, docker container spinning up only takes an extra second. So it is not worth making the feature for container reuse. Link to my code https://github.com/kevanpng/aws-sam-local .

For a fixed query, both my colleague and I have 4s invocation time on sam local. His is a windows machine. With giving the profile flag and the container reuse, it goes down to 2.5s in my ubuntu.

My colleague is running on mac and when he tried the same query with lambda reuse and profile flag, he still had 11-14 seconds to run.

Maybe it could be that docker is slow on mac?

kevanpng avatar Oct 11 '18 05:10 kevanpng

1 second is a world's difference when building an API and you expect to serve more than 1 request.

I think it's well worth the feature.

ghost avatar Oct 11 '18 14:10 ghost

@kevanpng Hey I was looking through your code to understand what exactly you did.. So basically, you create the container once with a fixed name, run the function, and on next invocation look for container with same name and simply container.exec_run instead of creating it from scratch again. Is my summary correct?

I am super surprised Docker container creation makes this big of a difference. We can certainly look deeper into this if it is becoming usability blocker.

sanathkr avatar Oct 11 '18 17:10 sanathkr