It’s a tough call. The amount of time you spend figuring out which libraries they let you use in python and node can end up being more headache than just having cron running on an ec2.
So, I’ve built some things that absorb cloudwatch logs and insert them into a database that worked with lambda, but needed special work to get psycopg2 installed to work with postgres. Then there’s data that comes from external apis, which I couldn’t get to work in lambda with python at all, so was easier to just spin up an ec2 and have a cron job do it.
I don’t remember the exact problem, but it wasn’t setting up vpc and nat. I believe it was because the api just pushes a huge csv, which I couldn’t get to download to s3 with the lambda process for some reason. Worked fine as a cron job on a micro instance, so that’s how it runs now.
The report is miles away from my experience. I’m seeing typical startup times of 5-6 seconds, and sometimes up to 10 seconds, for a function that itself typically takes under 100msec. I suspect the difference is that I’m coding in .Net, and maybe these tests were done with a Python function. My function is less than 1,000 lines of code. But when it starts up it reports consuming ~20MB. That must be almost all .Net overhead, and it’s taking that time to get .Net loaded. My understanding (from before .Net support was announced) is that Python is the fastest start-up, and JVM by far the worst - and .Net is probably similar to JVM.
So I’m going to stick with my keep-alive heartbeat calls.
The data also reveals that the time needed to establish a secure TLS connection to the API gateway from across North America—more than 200 milliseconds in some cases—is more significant than the Lambda execution time itself.
This is interesting. Minus the part about geography, I wonder if this is one factor that led to so much variation in my (warm) execution times. I saw responses of anything from 1.25msec to 127msec when executing an identical codepath. I also wonder how much my performance can be affected by other processes running on the same hardware – I don’t think Lambda guarantees a certain level of CPU access the way most EC2 instance types do.
This issue has been discussed many times for Google app engine with similar conclusions:. JVM had dramatically longer startup times then Python.
Last I heard the problem wasn’t solved so people were reporting to the sort of solution that you describe: a heartbeat.
On app engine you have more control of the servers so you could also address the problem by making adjustments to performance characteristics but that usually end up being an expensive solution.
I haven’t done anything to proactively warm the functions. But I have set up a scheduled event, pinging my function every few minutes. That seems to work well.
But this past weekend I had a problem, where my typical 5-6 second warmup suddenly jumped to 10 seconds - and I had my timeout set at 10! I had just released an update, and it kept failing even though it worked fine on my own machine (classic programmer line). It appears that if the first query fails with a timeout, lambda views the whole thing as a bust and tears down the whole environment - you can’t just call into the same “instance” the next time, with your warmup all paid for. So I just couldn’t get over that hump, until I upped the timeout to 15 seconds - all for my function that usually takes less than 100msec.
I really wonder why Amazon doesn’t seem to be keeping instances sitting around warm with a JVM or .Net VM already up, and ready to load a customer’s code; that ought to be equivalent to the much faster times I see on my own machine.
One thing I don’t know about at all is how this works for highly-used functions that need to scale out. My own isn’t yet being used in production, so I haven’t seen it under heavy, real load yet. Is there a way to proactively warm up the function before it’s put into real use? I really don’t want a real customer request to be stuck waiting for a multi-second warmup, and in fact I wonder if they’ll even send multiple requests at the new instance even before it’s fully up, so that a bunch of requests might get the slow response.
Because if you need that service you need to pay for it. Different services for different needs. When latent behavior is an unacceptable cost, you move to a different service.
Have you isolated the core functionality of your lambda function into a separate .net code library and tested that by itself? Sounds like it’s your code that’s taking that long, not lambda. We are seeing sub second cold start up times with our .Net based lambda functions. We’re finding equivalent code in node to only be slightly faster. It seems that .net should be giving better performance than jvm. We tried jvm before and the performance was lousy.
Unit tests running on my development box (which are all running in parallel, so eating more CPU) all complete in well under a second. The function is set up as an Alexa skill, but my unit tests attack that at both the outer interface, as well as straight into the internal code that’s below the level where the Alexa-related stuff happens. And once my lambda function is warmed up, they run much faster than that (mostly <100ms, as I said). So I can’t see anywhere else to allocate the lost time in those 5-6 second (and sometimes 10 second) first calls.
What region? I wonder if that’s the difference. Other than that, I have never seen more than 1 second start up time. Is your code using any third party external libraries?