3 ms·
Even though a container starts "damn fast" in Docker, you're still adding significant latency to each call of your function if it requires a new container.
by jitl 9y ago
Even though a container starts "damn fast" in Docker, you're still adding significant latency to each call of your function if it requires a new container.
$ time docker run alpine:3.6 sh -c exit
docker run alpine:3.6 sh -c exit 0.02s user 0.02s system 3% cpu 1.191 total
$ time sh -c exit
sh -c exit 0.00s user 0.01s system 94% cpu 0.007 total
Then add to that the cost of loading your function's code into memory. For an interpreted language, that is probably going to take a while as the runtime does a bunch of system calls and parses text files. Even for a compiled, statically-linked language like Go, the executable (a random binary I picked was 50MB) needs to be copied into RAM.
For this reason, Lambda tries to keep your containers/function-wrapper-applications booted up in RAM: https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ https://aws.amazon.com/blogs/compute/container-reuse-in-lamb...
- lobster_johnson 9y agoTrue, but that's Docker. There's nothing, that I know, that would make Linux containers inherently much slower than a fork. Amazon could conceivably also write their own container runtime that kept the container ready to run without actually starting the app (though I'm sure there's a lot more to it -- I don't know how Lambda is implemented).