0 votes
1 view
in AWS by (19.2k points)

Is scheduling a lambda function to get called every 20 mins with CloudWatch the best way to get rid of lambda cold start times? (not completely get rid of)...

Will this get pricey or is there something I am missing because I have it set up right now and I think it is working.

Before my cold start time would be like 10 seconds and every subsequent call would complete in like 80 ms. Now every call no matter how frequent is around 80 ms. Is this a good method until say your userbase grows, then you can turn this off?

My second option is just using beanstalk and having a server running 24/7 but that sounds expensive so I don't prefer it.

1 Answer

0 votes
by (44.6k points)

As far as I know, this is the only way to keep the function hot right now. It can get pricey only when you have a lot of those functions.

You'd have to calculate yourself how much do you pay for keeping your functions alive considering how many of them do you have, how long does it take to run them each time and how much memory do you need.

But once every 20 minutes is like 2000 times per month so if you utilize e.g. 128MB and make them finish below 100ms then you'll keep quite a lot of such functions alive at 20-minute intervals and still be under the free tier - it would be twenty seconds per month per function. You don't even need to flip it off after you get a much bigger load because it'll be irrelevant at this time. Besides you'll be able to never be sure to get a consistent load all the time so you might keep your heart beating code active even then.

Though my guess is that since it is so cheap to keep a function alive (especially if you have a special argument that makes them return immediately) and that the difference is so great (10 seconds vs. 80 ms) then just about everyone will do it - there's pretty much no excuse not to. In that case, I expect Amazon to either fight that practice (by making it hard or more expensive than it currently is - which wouldn't be a smart move) or to make it not needed in the future. If the distinction between hot and cold start was 100ms then nobody would bother. If it is 10 seconds then everyone needs to work around it.

There would forever have to be a difference between running a code that was run a second ago and a code that was run a month ago, because having all of them in RAM and prepared to go would waste plenty of resources, but I see no reason why that difference could not be made less noticeable or even have a few more steps instead of just hot and cold start.



 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...