denoland / deno-lambda

A deno runtime for AWS Lambda. Deploy deno via docker, SAM, serverless, or bundle it yourself.
868 stars 42 forks source link

How much the initialize time is different than standard Node environment? #37

Closed jerrygreen closed 4 years ago

jerrygreen commented 4 years ago

Most of us heard about that poor guy running that .NET environment, non-optimized for lambda with (supposedly) bloated with propagating lambda self executions leading to bloated price for this architecture on aws lambda.

So my question, - is there some differences in initialize time, for the Deno environment, comparing to Node environment? Maybe even some overhead?

hayd commented 4 years ago

This is kinda a hard question to answer...

The init duration for my deno functions is ~200ms-300ms (assuming deno is not doing any compiling). Node seems about the same ballpark (I saw it higher too, so this may depend on dependency size), but you're right node is likely better optimized. But I would argue deno init time is low enough to rarely be the concern...

There are tricks to keeping init time low, warm starts: https://serverless.com/blog/keep-your-lambdas-warm/ (Note: the init cost is only paid on a cold start)

Fundamentally Lambda executes events sequentially i.e. doesn't retrieve a second event until the first returns... see https://github.com/hayd/deno-lambda#warning.

Yet one of the great things about javascript is that it's async and easily handles many requests at the same time, so if that's your workload then EB/ASG/spots will be cheaper (I use a lot of these at work). That's true of node too.

This means you really have to think carefully when architecting your solutions: https://read.acloud.guru/save-time-and-money-with-aws-lambda-using-asynchronous-programming-3548ea65f751

I hope this answers the question!