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

Поделиться
HTML-код
  • Опубликовано: 30 ноя 2022
  • 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/Elfocrash/aws-videos
    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/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    Keep coding merch: keepcoding.shop
    #aws #dotnet

Комментарии • 72

  • @sikor02
    @sikor02 Год назад +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 Год назад +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 Год назад

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

  • @albertocorralesgarcia5106
    @albertocorralesgarcia5106 Год назад +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

  • @lordicemaniac
    @lordicemaniac Год назад +2

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

  • @tanglesites
    @tanglesites Год назад +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.

    • @user-uj8ts7pi9y
      @user-uj8ts7pi9y Месяц назад

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

  • @thegenxgamerguy6562
    @thegenxgamerguy6562 Год назад +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!

  • @slang25
    @slang25 Год назад +3

    This is the one I've been waiting for 🙂

  • @ReSpawNnL
    @ReSpawNnL Год назад +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.

  • @MarianoGomezBidondo
    @MarianoGomezBidondo Год назад

    Nick, great video! As always!.... Do you know if it can be used for minimal api?

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

  • @rick2591
    @rick2591 Год назад +4

    Is there a way to use native AOT for azure?

  • @dyrdai2658
    @dyrdai2658 Год назад

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

  • @nudemeth3152
    @nudemeth3152 Год назад

    Great video. Does it work with dynamic assembly loading?

  • @computer9764
    @computer9764 Год назад +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.

  • @InfinityFnatic
    @InfinityFnatic Год назад

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

  • @steinkoopjes
    @steinkoopjes Год назад +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).

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

  • @ezecel9
    @ezecel9 Год назад

    I love the video miniature

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

  • @Ianis58
    @Ianis58 Год назад +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.

  • @marcelofernandes8005
    @marcelofernandes8005 Год назад +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  Год назад +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 Год назад

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

  • @az6876
    @az6876 Год назад +2

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

  • @maksymkyian4920
    @maksymkyian4920 Год назад

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

  • @antonmartyniuk
    @antonmartyniuk Год назад

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

  • @hellfire1980
    @hellfire1980 Год назад

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

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

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

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

  • @superpcstation
    @superpcstation Год назад +1

    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.

  • @michaelakin766
    @michaelakin766 Год назад

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

  • @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  Год назад +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

  • @ethanrushbrook3314
    @ethanrushbrook3314 Год назад +1

    🤯

  • @NickTurpchinoff
    @NickTurpchinoff Год назад +5

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

    • @serverlessjames
      @serverlessjames Год назад +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

    • @NickTurpchinoff
      @NickTurpchinoff Год назад +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?

  • @SergeyKozachenko
    @SergeyKozachenko Год назад

    Is AWS Lambda has SnapStart enabled?

  • @JKhalaf
    @JKhalaf Год назад

    How does NativeAOT compare with Go?

  • @ronsijm
    @ronsijm Год назад +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 Год назад +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 RUclips channel demonstrating how to use it. ruclips.net/video/exRLCRHpvQE/видео.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

  • @paulpach
    @paulpach Год назад

    Does this work with Azure functions with Minimal API?

    • @nickchapsas
      @nickchapsas  Год назад +5

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

  • @nick_stelmakh
    @nick_stelmakh Год назад

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

  • @metaltyphoon
    @metaltyphoon Год назад

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

  • @jeroboam4486
    @jeroboam4486 Год назад +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  Год назад +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

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

    • @jeroboam4486
      @jeroboam4486 Год назад +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

  • @michaelakin766
    @michaelakin766 Год назад

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

    • @nickchapsas
      @nickchapsas  Год назад +1

      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 Год назад +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.

  • @Ristogod
    @Ristogod Год назад +4

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

  • @MicrosoftLifecam1
    @MicrosoftLifecam1 Год назад

    well if I get a bigger package 😏

  • @Denmaverick39
    @Denmaverick39 Год назад

    Haha does it mean this is hot start?

  • @weluvmusicz
    @weluvmusicz Год назад

    Billed duration.... omega lul

  • @pavl0britt207
    @pavl0britt207 Год назад

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