Тёмный

Using .NET’s NativeAOT to fix the biggest serverless issue 

Nick Chapsas
Подписаться 308 тыс.
Просмотров 29 тыс.
50% 1

Get $50 free AWS Credit by adding "AWS CREDIT #NICK" in the "Tell us about your project" area: bit.ly/nickaws
Get the source code: github.com/Elf...
Check out my courses: dometrain.com
Become a Patreon and get source code access: / nickchapsas
This video is sponsored by AWS
Hello everybody I'm Nick and in this video I will show you how you can get started with .NET 7's NativeAOT today and build your lambdas using a custom runtime that can run in AWS. NativeAOT compiles our code into native code and such a compilation can really help eliminate the biggest problem with C# serverless lambdas: cold starts.
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasG...
Follow me on Twitter: bit.ly/ChapsasT...
Connect on LinkedIn: bit.ly/ChapsasL...
Keep coding merch: keepcoding.shop
#aws #dotnet

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 72   
@sikor02
@sikor02 Год назад
That's nice. Recently I had to learn Go as the company I work with is migrating from dotnet to Go for mostly memory consumption reasons. With dotnet AOT I hope it will change and bring dotnet to microservices again as I don't really enjoy working with Go as I like with C#
@tylerkropp4380
@tylerkropp4380 Год назад
It's just "Go".
@EikeSchwass
@EikeSchwass Год назад
Would you consider making a video about TPL with threadpool interactions, execution context, async state machine and all things related and how you can easily run into thread pool starvation if you misuse these techniques? It's easy to find superficial explainations about these topics on the web, but an indepth guide to everything async would be really valuable I think! (copy pasted from another vid, in case you missed it)
@gui.ferreira
@gui.ferreira Год назад
Anyone that ever worked with Lambdas needs to be this excited 🤩
@albertocorralesgarcia5106
@albertocorralesgarcia5106 Год назад
Awesome video! NativeAOT seems very promising for lambdas. In a future video, it might be nice to test it with ARM64, as it is supposed to perform even better when lambdas are executed in graviton processors
@tanglesites
@tanglesites Год назад
Its rare when dealing with Development that you get both Performance and Savings in memory. I think we are use to the trade off, I can have faster, but have to sacrifice space, or vice-versa. This seems to be a win-win. Awesome stuff.
@クリス-p2k
@クリス-p2k 4 месяца назад
The biggest trade off is your sanity when dealing with trimming runtime errors
@rick2591
@rick2591 Год назад
Is there a way to use native AOT for azure?
@lordicemaniac
@lordicemaniac Год назад
this was my main complain why not to use c# in lambdas, like mandalorians would say "this is the way" :D
@slang25
@slang25 Год назад
This is the one I've been waiting for 🙂
@ReSpawNnL
@ReSpawNnL Год назад
What a coincidence. We were fiddling around with a Python 3.9 script that we use for authorizing, which includes boto3 to call and validate the JWT token against AWS services. That method sometimes took about 2000ms+ to execute, especially when it spun down and had to spin up again, basically cold (re)start. We eventually had to put 2048MBs of ram on that bad boy to get it anywhere near 50ms, not even any lower than that. Removing boto3 all together bumped it down to 5-10ms, which was fine. Now this cookie crumbles completely different. Makes me want to revisit that pesky crappy Python script.
@marsovac
@marsovac Год назад
why python if you need performance, it is the slowest thing on earth...
@ReSpawNnL
@ReSpawNnL Год назад
@@marsovac fully agree. Other devs dropped this in my lap. I saw NodeJS was a real posibility, too - don't know why they didn't go for that.
@thegenxgamerguy6562
@thegenxgamerguy6562 Год назад
This looks good to me. Maybe trying out some serverless stuff in the future is not such a bad idea after all. Thank you for this very interesting video!
@betterlifeexe4378
@betterlifeexe4378 Год назад
I am a proponent of near serverless & cashed for sites with logins/financial and return visitors, full serverless & cashed for no login/financial and return visitors, and whatever is easy for your simple one time use per user sites. The secure parts need a server, the rest should probably be pushed once and computed on their hardware.
@computer9764
@computer9764 Год назад
I've been wanting native AOT for years The problem is when things don't work in every case or without much setup, people attempt to use them and complain. .Net 7 released with required members being incompatible with the JSON source generators, so I expect to see similar issues with packages that aren't aware native aot is a thing.
@steinkoopjes
@steinkoopjes Год назад
Great as always! Quick question though, have you also considered benchmarking the case where you build for and run on arm64? AWS themselves claim even better performance for that option, though that should always be taken with a grain of salt. Speaking from experience, it's basically zero effort configuration-wise (in my case, using the .NET 6 LTS Runtime and provisioned with AWS CDK).
@Ianis58
@Ianis58 Год назад
Very interesting, thanks. I can see a possible use case where NativeAOT would be enabled for production environnement builds but not for test environnements builds: it would keep the pace quickly as before for test environnements deployments, but would allow better performances in production.
@kondziossj3
@kondziossj3 Год назад
For that reflection issue... They should say that each reference used a reflection and allow to have some attribute to say that some some lib explicit said that they not use reflection so overall that would be much easier to use that feature
@marcelofernandes8005
@marcelofernandes8005 Год назад
Hey @nickchapsas, amazing content! But why didn't you run the runtime example with .Net 7 as well? Any particular reason? It would be nice to see if all the improvements were from using AoT or if some of it was from the SDK optimizations. Nonetheless, amazing content!
@nickchapsas
@nickchapsas Год назад
I mentioned it in the video. AWS only supports the LTS version of .NET as runtimes so I couldn’t. There wouldn’t be a noticeable difference anyway for this example
@marcelofernandes8005
@marcelofernandes8005 Год назад
@@nickchapsas Ohhh my bad, didn't catch that part. Thanks 👍
@jeroboam4486
@jeroboam4486 Год назад
It's not a fair comparison : .net 7 added a lot of perfs so we can't determine which one is responsible for most of the perf boost, native AOT or .net 7. Also I noticed that AWS was billing you for much more time than what native had used : your first example took less than 30ms but they billed 147ms. It was less bad in the second example.
@nickchapsas
@nickchapsas Год назад
Actually, you are 100% wrong you either not running and benchmarks of your own or you haven't been paying attention to the release. .NET 6 actually has a faster startup time than .NET 7 on average for basic configuration. I left this point out because I want to make a dedicate video on .NET 6 and 7 performance, but unless you are using EF Core heavily (which for lambdas you shouldn't) then you won't see any performance boost on .NET 7 and even if you do use EF and you do see the increase, AOT's increase completely shadows that increase and ends up being faster yet again. For context, .NET 7 has an average startup of 140ms on basic configuration while for the exact same code .NET 6 has an average of 110ms. When it comes to request handling .NET 6 is still faster with 23ms for the weather endpoint compared to .NET 7 which averages 32ms. For extra extra context, Basic configuration is the default WebAPI which contains the WeatherController, with the Swagger stuff removed. Run those tests yourself and see, instead of speculating on what you are being shown by biased sources.
@gronkymug2590
@gronkymug2590 Год назад
@@nickchapsas Do you have a video explaining "EF Core heavily (which for lambdas you shouldn't)"?
@jeroboam4486
@jeroboam4486 Год назад
@@nickchapsas I'm not using Lambda, I just watched this video out of curiosity. When benchmarking something I expect to have only one variable that is different, by adding 2 it makes the benchmark less clear.
@alexisavls2601
@alexisavls2601 Год назад
@@gronkymug2590 I was going to comment the same thing. Hopefully we get the explanation :D
@MarianoGomezBidondo
@MarianoGomezBidondo Год назад
Nick, great video! As always!.... Do you know if it can be used for minimal api?
@assumingstraw5703
@assumingstraw5703 Год назад
Hey, great video. I'm new to AOT and Lambdas. I'm a bit confused about what's the best way to handle dependency injection. Do you have any videos/resources? When you add your CustomerRepo, you mention it's a pretty hacky way but I'm struggling to put together a better way. I couldn't get ServiceProvider to work without getting exceptions! Thanks and thanks for the great content as always!
@dyrdai2658
@dyrdai2658 Год назад
Thanks for the video. Are you going to give any discounts on your courses for the New Year?
@az6876
@az6876 Год назад
When SnapStart can be used with Net Core (maybe) the cold starts problem will be solved.
@antonmartyniuk
@antonmartyniuk Год назад
Native AoT is a game changer for sure. Bigger size of the lambda is not an issue actually
@disturp
@disturp Год назад
Does this work with .NET Minimal APIs? That's what I'm waiting for! :)
@serverlessjames
@serverlessjames Год назад
It will do, yes. There is a new release coming to our Lambda tooling for running ASP.NET on Lambda that allows a custom serialiser to be passed in. This will enable native AOT with minimal APIs on Lambda. In my tests, I've seen a ~500ms cold start for a 4 endpoint API talking to DynamoDB
@disturp
@disturp Год назад
@@serverlessjames That would be really nice. I'm a Senior Software Engineer, focusing on Backend APIs, and this makes me happy to hear. I have quite a few Minimal APIs and this would help me out a lot. Where can I keep tabs on the process of this Lambda Tooling?
@superpcstation
@superpcstation Год назад
Nick, does using NativeAOT better protects your app from reverse engineering (using tools like dotpeek etc)?
@banerjeesaikat6
@banerjeesaikat6 Год назад
Yes - IL is very easily de-compiled, while native code is basically machine code which might be much harder to de-compile.
@aracron
@aracron Год назад
Thank you for this. Do I need a single project per function with NativeAOT, or can I have multiple functions and use cmd override?
@aracron
@aracron Год назад
I think I answered my own question by spinning up a serverless NativeAOT template project. It already has what I was looking for.
@InfinityFnatic
@InfinityFnatic Год назад
Great video! Is it possible to use AOT with Entity Framework?
@maksymkyian4920
@maksymkyian4920 Год назад
Cool video, is it possible to do the same with Azure Functions?
@michaelakin766
@michaelakin766 Год назад
My biggest question is can I use this Native AOT with the Minimal Rest API.
@hellfire1980
@hellfire1980 Год назад
Is there a way to debug line by line on local environment before upload or deploy?
@JKhalaf
@JKhalaf Год назад
How does NativeAOT compare with Go?
@ezecel9
@ezecel9 Год назад
I love the video miniature
@ianknowles
@ianknowles Год назад
I have been waiting for this for a while. Does anyone know how to get the docker builder triggered. It's giving me cross compilation error on WIN?
@ronsijm
@ronsijm Год назад
Pretty cool. Does this work with Amazon.Lambda.AspNetCoreServer.Hosting ? Where basically I'm not hosting a small function, but just yeet a monolith into AWS and use it serverless?
@serverlessjames
@serverlessjames Год назад
Not yet, it will do shortly. There's an open PR that will be merged hopefully next week.
@serverlessjames
@serverlessjames Год назад
@ronsijm this is live now. I have a video on my RU-vid channel demonstrating how to use it. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-exRLCRHpvQE.html
@ronsijm
@ronsijm Год назад
@@serverlessjames Cool! Thanks for the update. I haven't updated my backend to dotnet7 yet, since it's not one of the supported Lambda runtimes yet. But if it works through NativeAOT that would be nice
@SergeyKozachenko
@SergeyKozachenko Год назад
Is AWS Lambda has SnapStart enabled?
@RandalGJunior
@RandalGJunior Год назад
It's possible to use a Lambda to host a grpcweb server? I have no backgroud on aws, and have a personal project of a BlazorWasm website that communicates with a api using grpc. Would be great to know if it's possible to go serverless.
@metaltyphoon
@metaltyphoon Год назад
There is still too much reflection based nugets everywhere for AOT to be really useful
@RicusNortje
@RicusNortje Год назад
I really wana do a comparison test using a Lambda that also has a VPC link.Will the OAT performance gain be negated by the ENI provisioning time?
@nickchapsas
@nickchapsas Год назад
For this, it’s irrelevant. We are only testing the impact on the .NET level. Any other infrastructure overhead is universal to any lambda technique
@nick_stelmakh
@nick_stelmakh Год назад
What is this terminal with highlighting and colorful folder/git branch and so on ?? Does sb know?
@nickchapsas
@nickchapsas Год назад
It's called oh-my-posh
@nick_stelmakh
@nick_stelmakh Год назад
@@nickchapsas thanks man)
@paulpach
@paulpach Год назад
Does this work with Azure functions with Minimal API?
@nickchapsas
@nickchapsas Год назад
AFAIK azure functions doesn’t support this. Couldn’t find any docs or cli support
@ethanrushbrook3314
@ethanrushbrook3314 Год назад
🤯
@Ristogod
@Ristogod Год назад
Meh, AWS, so they can turn off your code when they don't agree with your opinions. No Thanks.
@michaelakin766
@michaelakin766 Год назад
also, why does this not work with the arm64 - Which is supposed to be cheaper on aws
@nickchapsas
@nickchapsas Год назад
It does
@Octopie18
@Octopie18 Год назад
I can not deploy to arm64 because my processor architecture is x86 so the only option I can select is x86 since my machine is building it for that CPU arch. I'm assuming if you had an arm64 machine you could build for arm64 deploys.
@michaelakin766
@michaelakin766 Год назад
@@Octopie18 Is that true, even with using docker?
@Octopie18
@Octopie18 Год назад
@@michaelakin766 Actually forget what I said, it might hold true in the future but I just read: ".NET 7 ARM requires a newer version of GLIBC than is available in the provided.al2 Lambda runtime. .NET 7 functions that are deployed using the Arm64 architecture will fail to start with a runtime error stating the GLIBC version is below the required version for .NET 7." So it seems like .NET 7 cannot run on arm64 for AWS Lambdas. So you cannot currently build for it even if your CPU arch is arm64.
@Denmaverick39
@Denmaverick39 Год назад
Haha does it mean this is hot start?
@MicrosoftLifecam1
@MicrosoftLifecam1 Год назад
well if I get a bigger package 😏
@weluvmusicz
@weluvmusicz Год назад
Billed duration.... omega lul
@nudemeth3152
@nudemeth3152 Год назад
Great video. Does it work with dynamic assembly loading?
@pavl0britt207
@pavl0britt207 Год назад
Is there a way to debug line by line on local environment before upload or deploy?
Далее
Getting started with Queues in .NET using AWS SQS
44:01
Settling the Biggest Await Async Debate in .NET
14:47
Просмотров 144 тыс.
.NET 7 on AWS Lambda with NativeAOT
20:57
Просмотров 3,1 тыс.
Serverless Doesn't Make Sense
10:13
Просмотров 366 тыс.
NativeAOT in .NET 8 Has One Big Problem
14:47
Просмотров 28 тыс.
Using EF Core’s Coolest Feature to Audit in .NET
26:06
Serverless Computing in 100 Seconds
16:46
Просмотров 287 тыс.
Building a Serverless REST API in .NET with AWS Lambda
20:13
You are mocking the HttpClient the wrong way
13:56
Просмотров 49 тыс.
Microsoft FINALLY killed it
6:45
Просмотров 652 тыс.