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

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2024
  • 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

ความคิดเห็น • 72

  • @sikor02
    @sikor02 2 ปีที่แล้ว +41

    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#

  • @EikeSchwass
    @EikeSchwass 2 ปีที่แล้ว +29

    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 2 ปีที่แล้ว

    Anyone that ever worked with Lambdas needs to be this excited 🤩

  • @albertocorralesgarcia5106
    @albertocorralesgarcia5106 2 ปีที่แล้ว +5

    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

  • @betterlifeexe4378
    @betterlifeexe4378 ปีที่แล้ว +1

    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.

  • @tanglesites
    @tanglesites 2 ปีที่แล้ว +2

    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 5 หลายเดือนก่อน

      The biggest trade off is your sanity when dealing with trimming runtime errors

  • @ReSpawNnL
    @ReSpawNnL 2 ปีที่แล้ว +6

    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.

  • @lordicemaniac
    @lordicemaniac 2 ปีที่แล้ว +2

    this was my main complain why not to use c# in lambdas, like mandalorians would say "this is the way" :D

  • @rick2591
    @rick2591 2 ปีที่แล้ว +4

    Is there a way to use native AOT for azure?

  • @computer9764
    @computer9764 2 ปีที่แล้ว +3

    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.

  • @slang25
    @slang25 2 ปีที่แล้ว +3

    This is the one I've been waiting for 🙂

  • @steinkoopjes
    @steinkoopjes 2 ปีที่แล้ว +1

    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).

  • @thegenxgamerguy6562
    @thegenxgamerguy6562 2 ปีที่แล้ว +1

    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!

  • @kondziossj3
    @kondziossj3 2 ปีที่แล้ว

    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

  • @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 2 ปีที่แล้ว

    Thanks for the video. Are you going to give any discounts on your courses for the New Year?

  • @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.

  • @marcelofernandes8005
    @marcelofernandes8005 2 ปีที่แล้ว +3

    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  2 ปีที่แล้ว +3

      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 2 ปีที่แล้ว

      @@nickchapsas Ohhh my bad, didn't catch that part. Thanks 👍

  • @Ianis58
    @Ianis58 2 ปีที่แล้ว +2

    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.

  • @antonmartyniuk
    @antonmartyniuk 2 ปีที่แล้ว

    Native AoT is a game changer for sure. Bigger size of the lambda is not an issue actually

  • @michaelakin766
    @michaelakin766 2 ปีที่แล้ว

    My biggest question is can I use this Native AOT with the Minimal Rest API.

  • @superpcstation
    @superpcstation 2 ปีที่แล้ว +1

    Nick, does using NativeAOT better protects your app from reverse engineering (using tools like dotpeek etc)?

    • @banerjeesaikat6
      @banerjeesaikat6 2 ปีที่แล้ว

      Yes - IL is very easily de-compiled, while native code is basically machine code which might be much harder to de-compile.

  • @JKhalaf
    @JKhalaf 2 ปีที่แล้ว

    How does NativeAOT compare with Go?

  • @SergeyKozachenko
    @SergeyKozachenko ปีที่แล้ว

    Is AWS Lambda has SnapStart enabled?

  • @hellfire1980
    @hellfire1980 2 ปีที่แล้ว

    Is there a way to debug line by line on local environment before upload or deploy?

  • @maksymkyian4920
    @maksymkyian4920 ปีที่แล้ว

    Cool video, is it possible to do the same with Azure Functions?

  • @az6876
    @az6876 2 ปีที่แล้ว +2

    When SnapStart can be used with Net Core (maybe) the cold starts problem will be solved.

  • @RandalGJunior
    @RandalGJunior 2 ปีที่แล้ว

    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.

  • @InfinityFnatic
    @InfinityFnatic 2 ปีที่แล้ว

    Great video! Is it possible to use AOT with Entity Framework?

  • @nick_stelmakh
    @nick_stelmakh ปีที่แล้ว

    What is this terminal with highlighting and colorful folder/git branch and so on ?? Does sb know?

    • @nickchapsas
      @nickchapsas  ปีที่แล้ว +2

      It's called oh-my-posh

    • @nick_stelmakh
      @nick_stelmakh ปีที่แล้ว

      @@nickchapsas thanks man)

  • @ianknowles
    @ianknowles 2 ปีที่แล้ว

    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 2 ปีที่แล้ว +1

    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 2 ปีที่แล้ว +4

      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 TH-cam channel demonstrating how to use it. th-cam.com/video/exRLCRHpvQE/w-d-xo.html

    • @ronsijm
      @ronsijm ปีที่แล้ว +1

      @@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

  • @disturp
    @disturp 2 ปีที่แล้ว +5

    Does this work with .NET Minimal APIs? That's what I'm waiting for! :)

    • @serverlessjames
      @serverlessjames 2 ปีที่แล้ว +5

      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 2 ปีที่แล้ว +3

      @@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?

  • @RicusNortje
    @RicusNortje 2 ปีที่แล้ว

    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  2 ปีที่แล้ว +1

      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

  • @paulpach
    @paulpach 2 ปีที่แล้ว

    Does this work with Azure functions with Minimal API?

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +5

      AFAIK azure functions doesn’t support this. Couldn’t find any docs or cli support

  • @michaelakin766
    @michaelakin766 2 ปีที่แล้ว

    also, why does this not work with the arm64 - Which is supposed to be cheaper on aws

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +1

      It does

    • @Octopie18
      @Octopie18 2 ปีที่แล้ว

      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 2 ปีที่แล้ว

      @@Octopie18 Is that true, even with using docker?

    • @Octopie18
      @Octopie18 2 ปีที่แล้ว +1

      @@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.

  • @metaltyphoon
    @metaltyphoon 2 ปีที่แล้ว

    There is still too much reflection based nugets everywhere for AOT to be really useful

  • @jeroboam4486
    @jeroboam4486 2 ปีที่แล้ว +5

    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  2 ปีที่แล้ว +3

      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 2 ปีที่แล้ว +2

      @@nickchapsas Do you have a video explaining "EF Core heavily (which for lambdas you shouldn't)"?

    • @jeroboam4486
      @jeroboam4486 2 ปีที่แล้ว +3

      @@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

  • @ezecel9
    @ezecel9 2 ปีที่แล้ว

    I love the video miniature

  • @ethanrushbrook3314
    @ethanrushbrook3314 2 ปีที่แล้ว +1

    🤯

  • @Ristogod
    @Ristogod 2 ปีที่แล้ว +4

    Meh, AWS, so they can turn off your code when they don't agree with your opinions. No Thanks.

  • @MicrosoftLifecam1
    @MicrosoftLifecam1 2 ปีที่แล้ว

    well if I get a bigger package 😏

  • @Denmaverick39
    @Denmaverick39 2 ปีที่แล้ว

    Haha does it mean this is hot start?

  • @weluvmusicz
    @weluvmusicz 2 ปีที่แล้ว

    Billed duration.... omega lul

  • @pavl0britt207
    @pavl0britt207 2 ปีที่แล้ว

    Is there a way to debug line by line on local environment before upload or deploy?