Techniques to speed up initialization time in a Lambda environment? Compile schema / resolvers at build/deploy time? #1354
Unanswered
kevin-mitchell
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Are you providing string glob to |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently deploying a GraphQL API (
apollo-server
+type-graphql
+typeorm
) in a Lambda environment. It's what is often referred to as a "Monolambda" or "Lambdalith". Regardless of what you call it, it's incredibly slow to startup (roughly 6 seconds!).If you're not familiar with Lambda, your function may or may not be initialized on any given request, and if not then the entire initialization process has to happen. This means all of the resolvers have to be loaded, the schema has to be generated, etc.
In our current test environment, this takes around 6 seconds - which is of course an incredibly long time. Subsequent requests do not have this overhead.
We could move to "provisioned concurrency", essentially this keeps a number of lambda functions "warm" at all times which saves the init function from running (or at least running as often). This may end up being the best option for us, but it's also relatively expensive.
My question though is this: Is there a way (either built in, or something somebody has come up with) to speed this up? Some ideas I'm wondering about include:
There are likely a lot of other things to consider, I'd just really appreciate any input or ideas.
edit / update:
One thing I'm noticing when I run a profiler is that the thing that seems to take the most time when starting up my app (running in Apollo Server) is
fs
. Below I'm going to post some of the output from running the node profiler locally.With my 22 resolvers:
Same startup, but with only a single resolver
I'm not sure if this is useful in anyway, but it seems like there would be some opportunity for optimization here. Maybe I'm missing something or doing something wrong?
Beta Was this translation helpful? Give feedback.
All reactions