Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Web Api on AWS Lambda is slow upon first request

I'm deploying my .net core 2.1 application on AWS Lambda, I'm using AspNetCoreServer Package for proxy routing to my controllers, and I found the problema on this solution, in my first request lambda is very slow for executing the action controller, but in anothers requests is fast, I look in CloudWatch logs for understand whats is happen and i saw in logs that the longest time is in ControllerActionInvoker: Route Match to invoke my action, I would to know if i did anything wrong or is .net core is slow for aws lambda.

My logs evidencies:

Here is my first request log: Here is my first request log

And my second request log: second request log

Thank you

like image 606
Lucas Vieira Avatar asked Aug 30 '26 11:08

Lucas Vieira


2 Answers

In fact the first slow request is not only caused by the lambda cold start. With .Net Core in lambda you have 2 cold start : the cold start of the lambda itself and the cold start of .net core itself. In order to avoid these 2 cold start you have to :

  • Lambda cold start : Warm your lambda by calling it every 5 min
  • .Net Core cold start : Warm your .Net Core api by calling all your endpoint at startup

refer to this github issue to know more on the first slow request in .Net Core (still hope this problem will be fixed or better managed in next dotnet core releases, but right now you don't have better option)

like image 124
Hayha Avatar answered Sep 02 '26 06:09

Hayha


Cold start (first lambda invocation) is not the specific problem of .Net Core. You can find a timing comparison for different languages in this article.

like image 31
Roman Patutin Avatar answered Sep 02 '26 08:09

Roman Patutin