In order to understand what I’m going to talk about, you must know what is AWS Lambda, I talked about in this blog post where I went through getting started with Visual studio code and AWS Lambda, go through the intro section of that post before you proceed if you are new Lambda.
I know what is AWS Lambda, but .Net? Isn’t that very window’ey?
If you hate windows and hence hated .Net even more, I won’t blame you, .Net wasn’t modular, it forced you to stay on Windows (server costs!) and although it was always a fantastic platform to do whatever you wanted.. the ability of the platform to let you code an application the shittiest way possible and also the best way possible (believe it or not) led to a lot of people who were led astray to its dark side to think that .Net can simply never perform as well, at least not in the cost effective way that some other frameworks can.
All this changed with the introduction of .Net core which made the platform modular, open source and more importantly became cross-platform. .Net core therefore allowed people to develop using .Net core framework on Linux, Mac or Windows using the newly released Visual studio code which is also cross-platform (and free!). You can still use Visual Studio on Windows to get the full powered IDE on Windows and now there is even a preview mode of the same on Mac.
Web API is the Microsoft’s de facto solution for building http based services (REST services).
The actual blog, sans introductions
When I first heard about the AWS announcement regarding preview support for launching .Net core Web API’s on AWS Lambda, I was blown away. Although there has been first class support for .Net core in Lambda since 1st December, 2016 where you could make a single input Lambda function receiving binary/json data it is a whole another ball game if you can just put your existing .Net core Web API’s on Lambda with just a few tweaks, follow this AWS guide in how to do that.
How does it work.. Lambda..a single function hosting a Web API suite with lots of controllers?
Lambda is still the same, AWS now calls a function in your code defined in a base class called Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
available via the nuget package Amazon.Lambda.AspNetCoreServer which is in preview mode. The function then bootstraps the ASP.NET core framework allowing the rest of the request to flow through the Web API pipeline. Here is a trivialistic overview of the same for your pleasure:
In between my euphoria I also thought that what will be the startup latency of such a function, basically since Lambda functions are spun up on demand (while you pay by the 100ms blocks of your function execution time) and it has to bootstrap the entire Web API pipeline, how much will be the cold start time (when your function is called after a long/first time) and the warm up time (your function is continuously being called).
so…what are the performance numbers?
We will be talking about only the integration latency here which is the latency between when API gateway received the request and the time it took to allocate a Lambda function for that request till the time the latter successfully receives the command.
I ran a free load test from Load Impact and went upto 25 users on a step load. The code that I used was .Net core Web API (of course) with a single controller returning hardcoded values serializing in JSON and no compression was enabled. Here are the results:
The load test runner was in south Brazil and the API was in Oregon (US).
Average Integration latency: 89ms
Total number of requests sent: 139
I warmed up the function by only calling it once, the first call generally took > 2 seconds after 5-10 minutes of inactivity.
The load numbers isn’t in thousands, sure, couldn’t do more than that on a free account, it gives me a very good idea though.
In short, I am impressed and can’t wait for the package to come out from preview, thank you AWS!
If you liked this article, you can choose to follow this blog/subscribe to email alerts (top of sidebar or below comments in mobile) so that you know when any future posts come about.